Class: Ulpos::Client
- Inherits:
-
Object
- Object
- Ulpos::Client
- Defined in:
- lib/ulpos/client.rb
Instance Attribute Summary collapse
-
#app_key ⇒ Object
readonly
Returns the value of attribute app_key.
-
#app_secret ⇒ Object
readonly
Returns the value of attribute app_secret.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
Instance Method Summary collapse
-
#initialize(app_key = Ulpos.app_key, app_secret = Ulpos.app_secret, endpoint = Ulpos.endpoint) ⇒ Client
constructor
A new instance of Client.
- #invoke(method = nil, options = {}) ⇒ Object
Constructor Details
#initialize(app_key = Ulpos.app_key, app_secret = Ulpos.app_secret, endpoint = Ulpos.endpoint) ⇒ Client
Returns a new instance of Client.
6 7 8 9 10 |
# File 'lib/ulpos/client.rb', line 6 def initialize(app_key = Ulpos.app_key, app_secret = Ulpos.app_secret, endpoint = Ulpos.endpoint) @app_key = app_key @app_secret = app_secret @endpoint = endpoint end |
Instance Attribute Details
#app_key ⇒ Object (readonly)
Returns the value of attribute app_key.
4 5 6 |
# File 'lib/ulpos/client.rb', line 4 def app_key @app_key end |
#app_secret ⇒ Object (readonly)
Returns the value of attribute app_secret.
4 5 6 |
# File 'lib/ulpos/client.rb', line 4 def app_secret @app_secret end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
4 5 6 |
# File 'lib/ulpos/client.rb', line 4 def endpoint @endpoint end |
Instance Method Details
#invoke(method = nil, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ulpos/client.rb', line 12 def invoke(method = nil, = {}) params = { :appkey => @app_key, :timestamp => Time.now.to_i.to_s, :signature_method => 'md5', :method => method, :format => 'json' } params.merge!() str = params.sort.collect { |param| "#{param[0]}=#{param[1]}" }.join("&") sign_str = @app_key + params[:timestamp] + @app_secret + params[:signature_method] sign = Digest::MD5.hexdigest(sign_str) method = "/#{params[:method]}" if params[:method] url = "#{@endpoint}#{method}?#{str}&sign=#{sign}" response = Net::HTTP.get(URI.parse(url)) if params[:format] == 'json' JSON.parse(response) elsif params[:format] == 'xml' response else response end end |