Class: Cheddargetter::Client
- Inherits:
-
Object
- Object
- Cheddargetter::Client
- Includes:
- HTTParty
- Defined in:
- lib/cheddargetter/client.rb
Constant Summary collapse
- OptionModes =
[:customer, :data, :customer_and_data, :no_options]
Instance Attribute Summary collapse
-
#options_mode ⇒ Object
Returns the value of attribute options_mode.
-
#password ⇒ Object
Returns the value of attribute password.
-
#product_code ⇒ Object
Returns the value of attribute product_code.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #customers_delete_all ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #method_missing(method, *args, &block) ⇒ Object
- #post(url, options) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 |
# File 'lib/cheddargetter/client.rb', line 10 def initialize( = {}) self.username = [:username] || ["username"] self.password = [:password] || ["password"] self.product_code = [:product_code] || ["product_code"] raise(ArgumentError, "No username specified") unless username raise(ArgumentError, "No password specified") unless password raise(ArgumentError, "No product_code specified") unless product_code end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cheddargetter/client.rb', line 20 def method_missing(method, *args, &block) parts = method.to_s.split('_') response = post('/' + [parts.slice!(0, 2).join('/'), parts].flatten.join('-'), args) if response.parsed_response["error"] && response.parsed_response["error"]["__content__"] && response.parsed_response["error"]["__content__"] == 'Resource not found' raise NoMethodError.new(method.to_s) else ::Cheddargetter::Response.new(response) end end |
Instance Attribute Details
#options_mode ⇒ Object
Returns the value of attribute options_mode.
6 7 8 |
# File 'lib/cheddargetter/client.rb', line 6 def @options_mode end |
#password ⇒ Object
Returns the value of attribute password.
6 7 8 |
# File 'lib/cheddargetter/client.rb', line 6 def password @password end |
#product_code ⇒ Object
Returns the value of attribute product_code.
6 7 8 |
# File 'lib/cheddargetter/client.rb', line 6 def product_code @product_code end |
#username ⇒ Object
Returns the value of attribute username.
6 7 8 |
# File 'lib/cheddargetter/client.rb', line 6 def username @username end |
Instance Method Details
#customers_delete_all ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/cheddargetter/client.rb', line 41 def customers_delete_all #whacky url response = self.class.post( "https://cheddargetter.com/xml/customers/delete-all/confirm/#{Time.now.to_i}/productCode/#{product_code}", :basic_auth => {:username => username, :password => password} ) ::Cheddargetter::Response.new(response) end |
#post(url, options) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/cheddargetter/client.rb', line 31 def post(url, ) () response = self.class.post( full_url(url, ), :body => filter_customer_code_key(), :basic_auth => {:username => username, :password => password} ) end |