Class: InsideSales::Client
- Inherits:
-
Object
- Object
- InsideSales::Client
- Defined in:
- lib/inside_sales.rb
Constant Summary collapse
- Error =
Class.new(StandardError)
- AuthenticationError =
Class.new(Error)
Instance Attribute Summary collapse
-
#endpoint_url ⇒ Object
readonly
Returns the value of attribute endpoint_url.
Instance Method Summary collapse
-
#initialize(subdomain, username, password, token) ⇒ Client
constructor
A new instance of Client.
-
#login ⇒ Object
This is a special type of request that is not handled via method_missing because of the logic required to set the cookies.
-
#method_missing(meth, *args, &block) ⇒ Object
dynamically dispatch methods to the web service.
Constructor Details
#initialize(subdomain, username, password, token) ⇒ Client
Returns a new instance of Client.
14 15 16 17 |
# File 'lib/inside_sales.rb', line 14 def initialize(subdomain, username, password, token) @username, @password, @token, @subdomain = username, password, token, subdomain @endpoint_url ||= eval('"' + REST_API_URL + '"') end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
dynamically dispatch methods to the web service
32 33 34 |
# File 'lib/inside_sales.rb', line 32 def method_missing(meth, *args, &block) request(meth.to_s.camelize(:lower), [*args]) end |
Instance Attribute Details
#endpoint_url ⇒ Object (readonly)
Returns the value of attribute endpoint_url.
12 13 14 |
# File 'lib/inside_sales.rb', line 12 def endpoint_url @endpoint_url end |
Instance Method Details
#login ⇒ Object
This is a special type of request that is not handled via method_missing because of the logic required to set the cookies.
21 22 23 24 25 26 27 28 29 |
# File 'lib/inside_sales.rb', line 21 def login response = request(:login, [@username, @password, @token]) if response == "false" raise AuthenticationError, "could not authenticate, please check your credentials" else @cookies = response. response end end |