topdmc-client 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/README.md +5 -1
- data/lib/topdmc/resources/base.rb +55 -54
- data/lib/topdmc/resources/client.rb +1 -1
- data/lib/topdmc/resources/version.rb +1 -1
- data/lib/topdmc/topdmc.rb +3 -0
- data/topdmc-client.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5451782f925283b8ebc5c52f72a7663c66dfb007
|
4
|
+
data.tar.gz: b0326f215a47efe75938349c7b4db12da9e55495
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18cf315a76443f0f11ad6818be66f2b32e68dea1e15118fefdb2597bf12734840d48d82153193d747230cae0031b5bcff84dff026f697bab27b47a18790b0e5d
|
7
|
+
data.tar.gz: 15c150863108eb8c5aba7f50b984063f5be9c6d578b514f52ed8e52890b99fa1a432ccc827c2411250583fe00b9dc10dcbbe1a788428b967c1af4a6cbd9e5227
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -24,8 +24,12 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
require 'topdmc/resources/client'
|
26
26
|
|
27
|
+
```ruby
|
27
28
|
client = TopDMC::Client.new :client_id => '',:client_secure=>''
|
28
|
-
|
29
|
+
artist = client.artist.find('eEkZ3o')
|
30
|
+
puts artist
|
31
|
+
|
32
|
+
```
|
29
33
|
|
30
34
|
## Development
|
31
35
|
|
@@ -5,76 +5,77 @@ require 'uri'
|
|
5
5
|
require 'topdmc/resources/utils'
|
6
6
|
|
7
7
|
module TopDMC
|
8
|
-
|
8
|
+
module Resources
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
class Base
|
11
|
+
include TopDMC::Resources::Utils
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
def initialize(client)
|
14
|
+
@client = client
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
private
|
18
|
+
def perform_request(request_method, path, params={})
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
# 处理请求参数
|
21
|
+
base_params ={
|
22
|
+
timestamp: Time.now.to_i,
|
23
|
+
nonce: nonce,
|
24
|
+
client_id: @client.client_id
|
25
|
+
}
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
# get请求合并参数
|
28
|
+
if request_method=='GET' then
|
29
|
+
base_params.merge! params
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
# 对参数名称和参数值进行URL编码
|
33
|
+
encoded_params = base_params.map do |key, value|
|
34
|
+
[key, URI.encode_www_form_component(value.to_s)]
|
35
|
+
end
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
# 按参数名进行升序排列,如果key值相同之后按照value进行排序
|
38
|
+
sorted_params = encoded_params.sort
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
# 参数名和参数值之间用 “=” 号连接,参数和参数之间用 “&” 号连接
|
41
|
+
normalized = sorted_params.map do |item|
|
42
|
+
item.join('=')
|
43
|
+
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
sign_str = [request_method,
|
46
|
+
URI.encode_www_form_component(path),
|
47
|
+
URI.encode_www_form_component(normalized.join('&'))
|
48
|
+
].join('&')
|
49
49
|
|
50
|
-
|
51
|
-
|
50
|
+
sign = hmac_sha1_signature(@client.client_secure, sign_str)
|
51
|
+
base_params[:sign] = sign
|
52
52
|
|
53
|
-
|
54
|
-
|
53
|
+
# 处理请求地址
|
54
|
+
path = "#{@client.url}#{path}"
|
55
55
|
|
56
|
-
|
57
|
-
|
56
|
+
payload={}
|
57
|
+
payload = params if request_method=='POST'
|
58
58
|
|
59
|
+
begin
|
60
|
+
response = RestClient::Request.execute(
|
61
|
+
method: request_method,
|
62
|
+
url: path,
|
63
|
+
headers: {
|
64
|
+
params: base_params,
|
65
|
+
payload: payload,
|
66
|
+
user_agent: @client.user_agent,
|
67
|
+
:content_type => :json,
|
68
|
+
:accept => :json}
|
69
|
+
)
|
70
|
+
return JSON.parse(response.body)
|
71
|
+
rescue => e
|
59
72
|
begin
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
headers: {
|
64
|
-
params: base_params,
|
65
|
-
payload: payload,
|
66
|
-
:content_type => :json,
|
67
|
-
:accept => :json}
|
68
|
-
)
|
69
|
-
return JSON.parse(response.body)
|
70
|
-
rescue => e
|
71
|
-
begin
|
72
|
-
return JSON.parse(e.response.body)
|
73
|
-
rescue => ex
|
74
|
-
raise ex
|
75
|
-
end
|
73
|
+
return JSON.parse(e.response.body)
|
74
|
+
rescue => ex
|
75
|
+
raise ex
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
79
|
+
end
|
79
80
|
end
|
80
81
|
end
|
data/lib/topdmc/topdmc.rb
CHANGED
data/topdmc-client.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.summary = %q{TopDMC OpenAPI client}
|
13
13
|
spec.description = %q{TopDMC OpenAPI client}
|
14
|
-
spec.homepage = "http://
|
14
|
+
spec.homepage = "http://openapi.topdmc.com"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: topdmc-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- liangyali
|
@@ -64,7 +64,7 @@ files:
|
|
64
64
|
- lib/topdmc/resources/version.rb
|
65
65
|
- lib/topdmc/topdmc.rb
|
66
66
|
- topdmc-client.gemspec
|
67
|
-
homepage: http://
|
67
|
+
homepage: http://openapi.topdmc.com
|
68
68
|
licenses:
|
69
69
|
- MIT
|
70
70
|
metadata:
|