Class: Locaweb::Emailmarketing::HttpRequestAdapter
- Inherits:
-
Object
- Object
- Locaweb::Emailmarketing::HttpRequestAdapter
- Defined in:
- lib/locaweb-emailmarketing/adapters/http_request_adapter.rb
Instance Method Summary collapse
- #delete(uri) ⇒ Object
- #get(uri) ⇒ Object
-
#initialize(options) ⇒ HttpRequestAdapter
constructor
A new instance of HttpRequestAdapter.
- #post(uri, attributes) ⇒ Object
- #put(uri, attributes) ⇒ Object
Constructor Details
#initialize(options) ⇒ HttpRequestAdapter
Returns a new instance of HttpRequestAdapter.
6 7 8 9 |
# File 'lib/locaweb-emailmarketing/adapters/http_request_adapter.rb', line 6 def initialize() .assert_required_keys(required: [:auth_token, :base_url]) = end |
Instance Method Details
#delete(uri) ⇒ Object
32 33 34 35 |
# File 'lib/locaweb-emailmarketing/adapters/http_request_adapter.rb', line 32 def delete uri RestClient.delete "#{@options[:base_url]}/#{uri}", { "X-Auth-Token" => [:auth_token], accept: :json } end |
#get(uri) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/locaweb-emailmarketing/adapters/http_request_adapter.rb', line 11 def get uri begin JSON RestClient.get "#{@options[:base_url]}/#{uri}", { "X-Auth-Token" => [:auth_token], accept: :json } rescue RestClient::ResourceNotFound nil end end |
#post(uri, attributes) ⇒ Object
26 27 28 29 30 |
# File 'lib/locaweb-emailmarketing/adapters/http_request_adapter.rb', line 26 def post uri, attributes RestClient.post "#{@options[:base_url]}/#{uri}", attributes.to_json, { "X-Auth-Token" => [:auth_token], content_type: :json } end |
#put(uri, attributes) ⇒ Object
20 21 22 23 24 |
# File 'lib/locaweb-emailmarketing/adapters/http_request_adapter.rb', line 20 def put uri, attributes RestClient.put "#{@options[:base_url]}/#{uri}", attributes.to_json, { "X-Auth-Token" => [:auth_token], content_type: :json } end |