Module: Mugen
- Extended by:
- Mugen
- Included in:
- Mugen
- Defined in:
- lib/mugen.rb,
lib/mugen/job.rb,
lib/mugen/jobs.rb,
lib/mugen/client.rb,
lib/mugen/account.rb,
lib/mugen/service.rb,
lib/mugen/version.rb
Defined Under Namespace
Classes: Account, Client, Job, Jobs, Service
Constant Summary
collapse
- VERSION =
"0.2.1"
- @@errors =
[]
Instance Method Summary
collapse
Instance Method Details
#api_key ⇒ Object
31
32
33
|
# File 'lib/mugen.rb', line 31
def api_key
@api_key or raise "API_KEY is not specified"
end
|
#api_key=(key) ⇒ Object
27
28
29
|
# File 'lib/mugen.rb', line 27
def api_key=(key)
@api_key = key
end
|
#api_url ⇒ Object
23
24
25
|
# File 'lib/mugen.rb', line 23
def api_url
@api_url || 'http://api.sandbox.mygengo.com/v1/'
end
|
#api_url=(url) ⇒ Object
19
20
21
|
# File 'lib/mugen.rb', line 19
def api_url=(url)
@api_url = url
end
|
#errors ⇒ Object
43
44
45
|
# File 'lib/mugen.rb', line 43
def errors
@@errors || []
end
|
#private_key ⇒ Object
39
40
41
|
# File 'lib/mugen.rb', line 39
def private_key
@private_key or raise "PRIVATE_KEY is not specified"
end
|
#private_key=(key) ⇒ Object
35
36
37
|
# File 'lib/mugen.rb', line 35
def private_key=(key)
@private_key = key
end
|
#set_params(options = {}, method = :get) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/mugen.rb', line 58
def set_params(options = {}, method = :get)
params = ActiveSupport::OrderedHash.new
params.merge! '_method' => 'post' if method == :post
params.merge! 'api_key' => Mugen.api_key
params.merge! 'data' => options.to_json unless options.empty?
params.merge! 'ts' => Time.now.gmtime.to_i.to_s
if method == :get
params.merge! 'api_sig' => sign(Mugen.private_key, params)
else
params.merge! 'api_sig' => sign(Mugen.private_key, params.to_json.gsub('/', '\/'))
end
params
end
|
#sign(private_key, data) ⇒ Object
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/mugen.rb', line 47
def sign(private_key, data)
if Hash === data
sorted_keys = data.keys.sort
data = sorted_keys.zip(data.values_at(*sorted_keys)).map {|k, v|
"#{k}=#{CGI::escape(v.to_s)}"
} * '&'
end
HMAC::SHA1.hexdigest private_key, data
end
|