Class: Edm::EdmClient
- Inherits:
-
Object
- Object
- Edm::EdmClient
- Defined in:
- lib/edm.rb
Constant Summary collapse
- DOMAIN =
'http://edm.demohour.com'
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#secret ⇒ Object
Returns the value of attribute secret.
Instance Method Summary collapse
- #generate_sign(options = {}) ⇒ Object
-
#initialize(account, secret) ⇒ EdmClient
constructor
A new instance of EdmClient.
- #remote_request(http_method, url, options = {}) ⇒ Object
- #request(url, http_method, options = {}) ⇒ Object
Constructor Details
#initialize(account, secret) ⇒ EdmClient
Returns a new instance of EdmClient.
6 7 8 9 |
# File 'lib/edm.rb', line 6 def initialize(account, secret) @account = account @secret = secret end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
11 12 13 |
# File 'lib/edm.rb', line 11 def account @account end |
#secret ⇒ Object
Returns the value of attribute secret.
11 12 13 |
# File 'lib/edm.rb', line 11 def secret @secret end |
Instance Method Details
#generate_sign(options = {}) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/edm.rb', line 21 def generate_sign( = {}) if .length > 0 secret = self.secret str = .to_a.sort.map { |c| "#{c[0]}=#{c[1]}" }.join('&') sign = Digest::SHA1.hexdigest("#{str}#{secret}") end end |
#remote_request(http_method, url, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/edm.rb', line 29 def remote_request(http_method, url, = {}) url = DOMAIN + url case http_method when 'post' Net::HTTP.post_form(URI.parse(url), ) when 'get' Net::HTTP.get(URI.parse(url)) end end |
#request(url, http_method, options = {}) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/edm.rb', line 13 def request(url, http_method, = {}) sign = generate_sign() [:sign] = sign [:account_key] = self.account result = remote_request(http_method, url, ) return result.body end |