Skip to content

Commit

Permalink
Add support for configurable api endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickLef committed Jan 18, 2019
1 parent 0be20ae commit dce092e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ You can establish values for a number of SparkPost settings in the initializer.

```ruby
SparkPostRails.configure do |c|
c.sandbox = true # default: false
c.track_opens = true # default: false
c.track_clicks = true # default: false
c.return_path = '[email protected]' # default: nil
c.campaign_id = 'YOUR-CAMPAIGN' # default: nil
c.transactional = true # default: false
c.ip_pool = "MY-POOL" # default: nil
c.inline_css = true # default: false
c.html_content_only = true # default: false
c.subaccount = "123" # default: nil
c.api_endpoint = "https://api.eu.sparkpost.com/api/" # default: "https://api.sparkpost.com/api/"
c.sandbox = true # default: false
c.track_opens = true # default: false
c.track_clicks = true # default: false
c.return_path = '[email protected]' # default: nil
c.campaign_id = 'YOUR-CAMPAIGN' # default: nil
c.transactional = true # default: false
c.ip_pool = "MY-POOL" # default: nil
c.inline_css = true # default: false
c.html_content_only = true # default: false
c.subaccount = "123" # default: nil
end
```

Expand Down Expand Up @@ -82,6 +83,7 @@ If you are using `ActiveJob` and wish to do something special when the SparkPost
```ruby
ActionMailer::DeliveryJob.rescue_from(SparkPostRails::DeliveryException) do |exception|
# do something special with the error
# do something special with the error
end
```

Expand Down
3 changes: 3 additions & 0 deletions lib/sparkpost_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def self.configure

class Configuration
attr_accessor :api_key
attr_accessor :api_endpoint
attr_accessor :sandbox

attr_accessor :track_opens
Expand All @@ -45,6 +46,8 @@ def set_defaults
@api_key = ""
end

@api_endpoint = "https://api.sparkpost.com/api/"

@sandbox = false

@track_opens = false
Expand Down
3 changes: 1 addition & 2 deletions lib/sparkpost_rails/delivery_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,8 @@ def prepare_api_headers_from sparkpost_data
end

def post_to_api
url = "https://api.sparkpost.com/api/v1/transmissions"
uri = URI.join(SparkPostRails.configuration.api_endpoint, 'v1/transmissions')

uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

Expand Down
3 changes: 2 additions & 1 deletion spec/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
end

it "raises exception on error" do
stub_request(:any, "https://api.sparkpost.com/api/v1/transmissions").
uri = URI.join(SparkPostRails.configuration.api_endpoint, 'v1/transmissions')
stub_request(:any, uri.to_s).
to_return(body: "{\"errors\":[{\"message\":\"required field is missing\",\"description\":\"recipients or list_id required\",\"code\":\"1400\"}]}", status: 403)

test_email = Mailer.test_email
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
c.api_key = "TESTKEY1234"
end
end

stub_request(:any, "https://api.sparkpost.com/api/v1/transmissions").
uri = URI.join(SparkPostRails.configuration.api_endpoint, 'v1/transmissions')
stub_request(:any, uri.to_s).
to_return(body: "{\"results\":{\"total_rejected_recipients\":0,\"total_accepted_recipients\":1,\"id\":\"00000000000000000\"}}", status: 200)
end

Expand Down

0 comments on commit dce092e

Please sign in to comment.