Class: SlidePay::Client
- Inherits:
-
Object
- Object
- SlidePay::Client
- Defined in:
- lib/slidepay/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#email ⇒ Object
Returns the value of attribute email.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#password ⇒ Object
Returns the value of attribute password.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #authenticate(email = nil, password = nil) ⇒ Object
- #delete(request_params) ⇒ Object
- #destroy(resource) ⇒ Object
-
#get(request_params) ⇒ Object
Base Request Methods.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #is_authenticated? ⇒ Boolean
-
#list(resource) ⇒ Object
Resource Methods.
- #post(request_params) ⇒ Object
- #put(request_params) ⇒ Object
- #retrieve(resource) ⇒ Object
- #save(resource) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/slidepay/client.rb', line 5 def initialize(={}) if [:endpoint] @endpoint = [:endpoint] end if [:email] @email = [:email] end if [:password] @password = [:password] end if [:token] @token = [:token] end if [:api_key] @api_key = [:api_key] end end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
3 4 5 |
# File 'lib/slidepay/client.rb', line 3 def api_key @api_key end |
#email ⇒ Object
Returns the value of attribute email.
3 4 5 |
# File 'lib/slidepay/client.rb', line 3 def email @email end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
3 4 5 |
# File 'lib/slidepay/client.rb', line 3 def endpoint @endpoint end |
#password ⇒ Object
Returns the value of attribute password.
3 4 5 |
# File 'lib/slidepay/client.rb', line 3 def password @password end |
#token ⇒ Object
Returns the value of attribute token.
3 4 5 |
# File 'lib/slidepay/client.rb', line 3 def token @token end |
Instance Method Details
#authenticate(email = nil, password = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/slidepay/client.rb', line 27 def authenticate(email=nil, password=nil) email = email || @email password = password || @password response = SlidePay.retrieve_token(email, password) if response.was_successful? @endpoint = "#{response.endpoint}" @token = response.data true else false end end |
#delete(request_params) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/slidepay/client.rb', line 64 def delete(request_params) = {} if request_params.is_a? String = { :path => request_params, :api_key => @api_key, :token => @token, :endpoint => @endpoint } else = request_params.merge! api_key: @api_key, token: @token, endpoint: @endpoint end SlidePay.delete() end |
#destroy(resource) ⇒ Object
98 99 100 |
# File 'lib/slidepay/client.rb', line 98 def destroy(resource) resource.destroy(api_key: @api_key, token: @token, endpoint: @endpoint) end |
#get(request_params) ⇒ Object
Base Request Methods
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/slidepay/client.rb', line 43 def get(request_params) = {} if request_params.is_a? String = { :path => request_params, :api_key => @api_key, :token => @token, :endpoint => @endpoint } else = request_params.merge! api_key: @api_key, token: @token, endpoint: @endpoint end SlidePay.get() end |
#is_authenticated? ⇒ Boolean
23 24 25 |
# File 'lib/slidepay/client.rb', line 23 def is_authenticated? @token != nil || @api_key != nil end |
#list(resource) ⇒ Object
Resource Methods
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/slidepay/client.rb', line 76 def list(resource) response = SlidePay.get(path: resource.url_root, api_key: @api_key, token: @token, endpoint: @endpoint) if response.was_successful? resources = [] response.data.each do |resource_instance| resources.push resource.class.new(resource_instance) end else resources = [] end resources end |
#post(request_params) ⇒ Object
59 60 61 62 |
# File 'lib/slidepay/client.rb', line 59 def post(request_params) request_params.merge! api_key: @api_key, token: @token, endpoint: @endpoint SlidePay.post(request_params) end |
#put(request_params) ⇒ Object
54 55 56 57 |
# File 'lib/slidepay/client.rb', line 54 def put(request_params) request_params.merge! api_key: @api_key, token: @token, endpoint: @endpoint SlidePay.put(request_params) end |
#retrieve(resource) ⇒ Object
90 91 92 |
# File 'lib/slidepay/client.rb', line 90 def retrieve(resource) resource.retrieve(api_key: @api_key, token: @token, endpoint: @endpoint) end |
#save(resource) ⇒ Object
94 95 96 |
# File 'lib/slidepay/client.rb', line 94 def save(resource) resource.save(api_key: @api_key, token: @token, endpoint: @endpoint) end |