Class: Mailbluster::Client
- Inherits:
-
Object
- Object
- Mailbluster::Client
- Defined in:
- lib/mailbluster/client.rb
Constant Summary collapse
- Error =
Class.new(StandardError)
- Forbidden =
Class.new(Error)
- NotFound =
Class.new(Error)
- UnprocessableEntity =
Class.new(Error)
- RESOURCES =
["leads", "fields", "products", "orders"].freeze
Instance Method Summary collapse
- #delete(subpath) ⇒ Object
- #get(subpath, query_params: nil) ⇒ Object
-
#initialize(api_key = nil, logger = nil) ⇒ Client
constructor
A new instance of Client.
- #post(subpath, payload) ⇒ Object
- #put(subpath, payload = {}) ⇒ Object
- #resource(resource_type) ⇒ Object
Constructor Details
#initialize(api_key = nil, logger = nil) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 |
# File 'lib/mailbluster/client.rb', line 13 def initialize(api_key = nil, logger = nil) @api_key = api_key || Mailbluster.configuration.api_key || ENV["MAILBLUSTER_API_KEY"] @api_url = Mailbluster.configuration.api_url || ENV["MAILBLUSTER_API_URL"] @logger = logger || Mailbluster.configuration.logger end |
Instance Method Details
#delete(subpath) ⇒ Object
47 48 49 |
# File 'lib/mailbluster/client.rb', line 47 def delete(subpath) request(:delete, subpath) end |
#get(subpath, query_params: nil) ⇒ Object
35 36 37 |
# File 'lib/mailbluster/client.rb', line 35 def get(subpath, query_params: nil) request(:get, subpath, query_params) end |
#post(subpath, payload) ⇒ Object
39 40 41 |
# File 'lib/mailbluster/client.rb', line 39 def post(subpath, payload) request(:post, subpath, payload) end |
#put(subpath, payload = {}) ⇒ Object
43 44 45 |
# File 'lib/mailbluster/client.rb', line 43 def put(subpath, payload = {}) request(:put, subpath, payload) end |
#resource(resource_type) ⇒ Object
23 24 25 26 27 |
# File 'lib/mailbluster/client.rb', line 23 def resource(resource_type) raise ArgumentError, "Invalid resource type" unless RESOURCES.include?(resource_type) ResourceType.new(self, resource_type) end |