topdmc-client 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f68b09ef7b59d1381229933e3f80a23b828181f
4
- data.tar.gz: 461446b46919ec3b6415dc2d8e93f5d20bc20b48
3
+ metadata.gz: 5451782f925283b8ebc5c52f72a7663c66dfb007
4
+ data.tar.gz: b0326f215a47efe75938349c7b4db12da9e55495
5
5
  SHA512:
6
- metadata.gz: 5571b4958e4d061efce87755b053f1bb59a8196e4431b37affc46cda0daccbe830f4746f81a860456e3c84f5ca7746b973667e601296e4d13e33c5f0b34835e9
7
- data.tar.gz: f4a592b116f4d07a2693f36d221f8134fbaaf0853241be7552b02a9835001d97b2a10da85342c815c9f66bfbe04332796dc92bc25b28701394dd03ee2861ecfc
6
+ metadata.gz: 18cf315a76443f0f11ad6818be66f2b32e68dea1e15118fefdb2597bf12734840d48d82153193d747230cae0031b5bcff84dff026f697bab27b47a18790b0e5d
7
+ data.tar.gz: 15c150863108eb8c5aba7f50b984063f5be9c6d578b514f52ed8e52890b99fa1a432ccc827c2411250583fe00b9dc10dcbbe1a788428b967c1af4a6cbd9e5227
data/.gitignore CHANGED
@@ -8,4 +8,5 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
 
11
- .idea/
11
+ .idea/
12
+ *.gem
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
- albums = client.artist.get('eEkZ3o')
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
- module Resources
8
+ module Resources
9
9
 
10
- class Base
11
- include TopDMC::Resources::Utils
10
+ class Base
11
+ include TopDMC::Resources::Utils
12
12
 
13
- def initialize(client)
14
- @client = client
15
- end
13
+ def initialize(client)
14
+ @client = client
15
+ end
16
16
 
17
- private
18
- def perform_request(request_method, path, params={})
17
+ private
18
+ def perform_request(request_method, path, params={})
19
19
 
20
- # 处理请求参数
21
- base_params ={
22
- timestamp: Time.now.to_i,
23
- nonce: nonce,
24
- client_id: @client.client_id
25
- }
20
+ # 处理请求参数
21
+ base_params ={
22
+ timestamp: Time.now.to_i,
23
+ nonce: nonce,
24
+ client_id: @client.client_id
25
+ }
26
26
 
27
- # get请求合并参数
28
- if request_method=='GET' then
29
- base_params.merge! params
30
- end
27
+ # get请求合并参数
28
+ if request_method=='GET' then
29
+ base_params.merge! params
30
+ end
31
31
 
32
- # 对参数名称和参数值进行URL编码
33
- encoded_params = base_params.map do |key, value|
34
- [key, URI.encode_www_form_component(value.to_s)]
35
- end
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
- # 按参数名进行升序排列,如果key值相同之后按照value进行排序
38
- sorted_params = encoded_params.sort
37
+ # 按参数名进行升序排列,如果key值相同之后按照value进行排序
38
+ sorted_params = encoded_params.sort
39
39
 
40
- # 参数名和参数值之间用 “=” 号连接,参数和参数之间用 “&” 号连接
41
- normalized = sorted_params.map do |item|
42
- item.join('=')
43
- end
40
+ # 参数名和参数值之间用 “=” 号连接,参数和参数之间用 “&” 号连接
41
+ normalized = sorted_params.map do |item|
42
+ item.join('=')
43
+ end
44
44
 
45
- sign_str = [request_method,
46
- URI.encode_www_form_component(path),
47
- URI.encode_www_form_component(normalized.join('&'))
48
- ].join('&')
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
- sign = hmac_sha1_signature(@client.client_secure, sign_str)
51
- base_params[:sign] = sign
50
+ sign = hmac_sha1_signature(@client.client_secure, sign_str)
51
+ base_params[:sign] = sign
52
52
 
53
- # 处理请求地址
54
- path = "#{@client.url}#{path}"
53
+ # 处理请求地址
54
+ path = "#{@client.url}#{path}"
55
55
 
56
- payload={}
57
- payload = params if request_method=='POST'
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
- response = RestClient::Request.execute(
61
- method: request_method,
62
- url: path,
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
@@ -15,7 +15,7 @@ module TopDMC
15
15
  end
16
16
 
17
17
  def user_agent
18
- @user_agent ||= "TopDMC/#{TopDMC::Client::VERSION}"
18
+ @user_agent ||= "TopDMC/#{TopDMC::Resources::VERSION}"
19
19
  end
20
20
 
21
21
  def artist
@@ -1,5 +1,5 @@
1
1
  module TopDMC
2
2
  module Resources
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
data/lib/topdmc/topdmc.rb CHANGED
@@ -1,2 +1,5 @@
1
1
  require 'topdmc/resources/client'
2
2
 
3
+ client = TopDMC::Client.new :client_id => '',:client_secure=>''
4
+ artist = client.artist.find('eEkZ3o')
5
+ puts artist
@@ -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://www.topdmc.com"
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.1
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://www.topdmc.com
67
+ homepage: http://openapi.topdmc.com
68
68
  licenses:
69
69
  - MIT
70
70
  metadata: