Class: Zooz::Request
- Inherits:
-
Object
- Object
- Zooz::Request
- Defined in:
- lib/zooz/request.rb,
lib/zooz/request/open.rb,
lib/zooz/request/verify.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#app_key ⇒ Object
Returns the value of attribute app_key.
-
#cmd ⇒ Object
Returns the value of attribute cmd.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#response_type ⇒ Object
Returns the value of attribute response_type.
-
#sandbox ⇒ Object
Returns the value of attribute sandbox.
-
#unique_id ⇒ Object
Returns the value of attribute unique_id.
Instance Method Summary collapse
-
#get_param ⇒ Object
Get a request parameter.
-
#initialize ⇒ Request
constructor
A new instance of Request.
-
#is_sandbox? ⇒ Boolean
Whether the request will be sent to sandbox.
-
#request ⇒ Object
Send a request to the server, returns a Zooz::Response object or false.
-
#set_param(name, value) ⇒ Object
Set a request parameter.
-
#url ⇒ Object
Get the URL of the API, based on whether in sandbox mode or not.
-
#valid? ⇒ Boolean
Whether the request object is valid for requesting.
Constructor Details
#initialize ⇒ Request
Returns a new instance of Request.
9 10 11 12 13 14 |
# File 'lib/zooz/request.rb', line 9 def initialize @params = {} @errors = [] @response_type = 'NVP' @sandbox = false end |
Instance Attribute Details
#app_key ⇒ Object
Returns the value of attribute app_key.
6 7 8 |
# File 'lib/zooz/request.rb', line 6 def app_key @app_key end |
#cmd ⇒ Object
Returns the value of attribute cmd.
6 7 8 |
# File 'lib/zooz/request.rb', line 6 def cmd @cmd end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
7 8 9 |
# File 'lib/zooz/request.rb', line 7 def errors @errors end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
7 8 9 |
# File 'lib/zooz/request.rb', line 7 def params @params end |
#response_type ⇒ Object
Returns the value of attribute response_type.
6 7 8 |
# File 'lib/zooz/request.rb', line 6 def response_type @response_type end |
#sandbox ⇒ Object
Returns the value of attribute sandbox.
6 7 8 |
# File 'lib/zooz/request.rb', line 6 def sandbox @sandbox end |
#unique_id ⇒ Object
Returns the value of attribute unique_id.
6 7 8 |
# File 'lib/zooz/request.rb', line 6 def unique_id @unique_id end |
Instance Method Details
#get_param ⇒ Object
Get a request parameter.
22 23 24 |
# File 'lib/zooz/request.rb', line 22 def get_param @params[name] end |
#is_sandbox? ⇒ Boolean
Whether the request will be sent to sandbox.
27 28 29 |
# File 'lib/zooz/request.rb', line 27 def is_sandbox? @sandbox == true end |
#request ⇒ Object
Send a request to the server, returns a Zooz::Response object or false. If returning false, the @errors attribute is populated.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/zooz/request.rb', line 39 def request return false unless valid? http_response = HTTParty.post(url, :format => :plain, :query => @params.merge({ :cmd => @cmd }), :headers => { 'ZooZ-Unique-ID' => @unique_id, 'ZooZ-App-Key' => @app_key, 'ZooZ-Response-Type' => @response_type, }) response = Response.new response.request = self response.http_response = http_response unless response.success? @errors = response.errors return false end response end |
#set_param(name, value) ⇒ Object
Set a request parameter.
17 18 19 |
# File 'lib/zooz/request.rb', line 17 def set_param name, value @params[name] = value end |
#url ⇒ Object
Get the URL of the API, based on whether in sandbox mode or not.
32 33 34 35 |
# File 'lib/zooz/request.rb', line 32 def url (is_sandbox? ? 'https://sandbox.zooz.co' : 'https://app.zooz.com') + '/mobile/SecuredWebServlet' end |
#valid? ⇒ Boolean
Whether the request object is valid for requesting.
59 60 61 62 63 64 65 66 |
# File 'lib/zooz/request.rb', line 59 def valid? @errors = [] @errors << 'unique_id is required' if @unique_id.nil? @errors << 'app_key is required' if @app_key.nil? @errors << 'cmd is required' if @cmd.nil? @errors << 'response_type is required' if @response_type.nil? @errors.empty? end |