Class: Yclients::Api::Client
- Inherits:
-
Object
- Object
- Yclients::Api::Client
- Includes:
- Auth, Companies, ServiceCategories
- Defined in:
- lib/yclients/api/client.rb
Constant Summary
Constants included from ServiceCategories
ServiceCategories::URL1, ServiceCategories::URL2
Constants included from Companies
Yclients::Api::Companies::URL1, Yclients::Api::Companies::URL2
Constants included from Auth
Instance Attribute Summary collapse
-
#login ⇒ Object
Returns the value of attribute login.
-
#partner_token ⇒ Object
Returns the value of attribute partner_token.
-
#password ⇒ Object
Returns the value of attribute password.
-
#user_token ⇒ Object
Returns the value of attribute user_token.
Instance Method Summary collapse
- #has_user_token? ⇒ Boolean
- #headers(args = {auth: false}) ⇒ Object
-
#initialize(args = {}) ⇒ Client
constructor
A new instance of Client.
- #query_param(key, value, type) ⇒ Object
Methods included from ServiceCategories
#service_categories, #service_category
Methods included from Companies
Methods included from Auth
Constructor Details
#initialize(args = {}) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 |
# File 'lib/yclients/api/client.rb', line 9 def initialize(args={}) @partner_token = args[:partner_token] or raise NoPartnerToken @user_token = args[:user_token] @login = args[:login] @password = args[:password] end |
Instance Attribute Details
#login ⇒ Object
Returns the value of attribute login.
7 8 9 |
# File 'lib/yclients/api/client.rb', line 7 def login @login end |
#partner_token ⇒ Object
Returns the value of attribute partner_token.
7 8 9 |
# File 'lib/yclients/api/client.rb', line 7 def partner_token @partner_token end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/yclients/api/client.rb', line 7 def password @password end |
#user_token ⇒ Object
Returns the value of attribute user_token.
7 8 9 |
# File 'lib/yclients/api/client.rb', line 7 def user_token @user_token end |
Instance Method Details
#has_user_token? ⇒ Boolean
16 17 18 |
# File 'lib/yclients/api/client.rb', line 16 def has_user_token? !!@user_token end |
#headers(args = {auth: false}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/yclients/api/client.rb', line 47 def headers(args={auth: false}) if args[:auth] { 'Authorization' => "Bearer #{@partner_token}, User #{@user_token}", "Content-Type" => 'application/json' } else { 'Authorization' => "Bearer #{@partner_token}", "Content-Type" => 'application/json' } end end |
#query_param(key, value, type) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/yclients/api/client.rb', line 20 def query_param(key, value, type) case type when :numeric if value.respond_to?(:to_i) && value.to_i > 0 { key => value } else {} end when :boolean if value == true { key => 1 } elsif value == false { key => 0 } else {} end when :string if value.kind_of?(String) && value.length > 0 { key => value } else {} end else {} end end |