Class: Edm::EdmClient

Inherits:
Object
  • Object
show all
Defined in:
lib/edm.rb

Constant Summary collapse

DOMAIN =
'http://edm.demohour.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account, secret) ⇒ EdmClient

Returns a new instance of EdmClient.



6
7
8
9
# File 'lib/edm.rb', line 6

def initialize(, secret)
  @account = 
  @secret = secret
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



11
12
13
# File 'lib/edm.rb', line 11

def 
  @account
end

#secretObject

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(options = {})
  if options.length > 0
    secret = self.secret
    str = options.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, options = {})
  url = DOMAIN + url
  case http_method
  when 'post'
    Net::HTTP.post_form(URI.parse(url), options)
  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, options = {})
  sign = generate_sign(options)
  options[:sign] = sign
  options[:account_key] = self.
  result = remote_request(http_method, url, options)
  return result.body
end