grooveshark 0.2.9 → 0.2.10

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: b4b7dfe5b1d75551f6d9991500bd51410105bbf6
4
- data.tar.gz: a0e90517ea68482399f001c63c9e92f2108c0fc5
3
+ metadata.gz: 4d602ca3fbcfdc5d9812fb69bd45e890f25f5b36
4
+ data.tar.gz: fd049697921040644c38404c77374c2b625622fe
5
5
  SHA512:
6
- metadata.gz: 203b0405c3b0d4b4c9d95aedb3a5665c3219914943306e927ad48c7a4eb3b97cb1c99ee756660140fa201814787af668b1f1f7efb9be01f8f01f60bb17ccbf7f
7
- data.tar.gz: 2458b45328a4a59b8876043196b72ab7c62ad8edc3ff9a284be0da13adc57314225bb5d5fbb628b1f5c1a199135a27ff7fc2aa3a6a1eb04dbc3c703b3c60a377
6
+ metadata.gz: e6d345fbb7bf7e58eaf8ceb38c9c2b32d604f8e5e60be3461acacb4dc1028d9f23c31b46f766d64b6ca2b2501dcd4e904a2940f727163841991ef03a0dfdca84
7
+ data.tar.gz: 5c1a411ae739e3c352ab7c0df69eff39e7234644860619cce1221edf0aa1b19cb48616adf90f194c50540b64fc67bf21452346437699838d26401f985d99d44c
@@ -5,9 +5,8 @@ module Grooveshark
5
5
 
6
6
  def initialize(params = {})
7
7
  @ttl = params[:ttl] || 120 # 2 minutes
8
- @session, @country = get_session_and_country
9
8
  @uuid = UUID.new.generate.upcase
10
- get_comm_token
9
+ get_token_data
11
10
  end
12
11
 
13
12
  # Authenticate user
@@ -89,32 +88,28 @@ module Grooveshark
89
88
  get_song_url_by_id(song.id)
90
89
  end
91
90
 
92
- def get_session_and_country
91
+ def get_token_data
93
92
  response = RestClient.get('http://grooveshark.com')
94
- session = response.headers[:set_cookie].to_s.scan(/PHPSESSID=([a-z\d]{32});/i).flatten.first
95
93
 
96
94
  preload_regex = /gsPreloadAjax\(\{url: '\/preload.php\?(.*)&hash=' \+ clientPage\}\)/
97
95
  preload_id = response.to_s.scan(preload_regex).flatten.first
98
96
  preload_url = "http://grooveshark.com/preload.php?#{preload_id}&getCommunicationToken=1&hash=%2F"
99
97
  preload_response = RestClient.get(preload_url)
100
98
 
101
- config_json = preload_response.to_s.scan(/window.tokenData = (.*);/).flatten.first
102
- raise GeneralError, "gsConfig not found" if not config_json
103
- config = JSON.parse(config_json)['getGSConfig']
104
- [session, config['country']]
105
- end
106
-
107
- # Get communication token
108
- def get_comm_token
109
- @comm_token = nil # request() uses it
110
- @comm_token = request('getCommunicationToken', {:secretKey => Digest::MD5.hexdigest(@session)}, true)
99
+ token_data_json = preload_response.to_s.scan(/window.tokenData = (.*);/).flatten.first
100
+ raise GeneralError, "token data not found" if not token_data_json
101
+ token_data = JSON.parse(token_data_json)
102
+ @comm_token = token_data['getCommunicationToken']
111
103
  @comm_token_ttl = Time.now.to_i
104
+ config = token_data['getGSConfig']
105
+ @country = config['country']
106
+ @session = config['sessionID']
112
107
  end
113
108
 
114
109
  # Sign method
115
110
  def create_token(method)
116
111
  rnd = get_random_hex_chars(6)
117
- salt = 'gooeyFlubber'
112
+ salt = "gooeyFlubber"
118
113
  plain = [method, @comm_token, salt, rnd].join(':')
119
114
  hash = Digest::SHA1.hexdigest(plain)
120
115
  "#{rnd}#{hash}"
@@ -128,7 +123,7 @@ module Grooveshark
128
123
  # Perform API request
129
124
  def request(method, params={}, secure=false)
130
125
  refresh_token if @comm_token
131
-
126
+
132
127
  url = "#{secure ? 'https' : 'http'}://grooveshark.com/more.php?#{method}"
133
128
  body = {
134
129
  'header' => {
@@ -143,7 +138,6 @@ module Grooveshark
143
138
  'parameters' => params
144
139
  }
145
140
  body['header']['token'] = create_token(method) if @comm_token
146
-
147
141
  begin
148
142
  data = RestClient.post(url, body.to_json, {'Content-Type' => 'application/json'})
149
143
  rescue Exception => ex
@@ -162,7 +156,7 @@ module Grooveshark
162
156
 
163
157
  # Refresh communications token on ttl
164
158
  def refresh_token
165
- get_comm_token if Time.now.to_i - @comm_token_ttl > @ttl
159
+ get_token_data if Time.now.to_i - @comm_token_ttl > @ttl
166
160
  end
167
161
  end
168
162
  end
@@ -1,3 +1,3 @@
1
1
  module Grooveshark
2
- VERSION = "0.2.9"
2
+ VERSION = "0.2.10"
3
3
  end
@@ -17,7 +17,7 @@ describe 'Client' do
17
17
  it 'should have a valid token' do
18
18
  @gs = Grooveshark::Client.new
19
19
  @gs.comm_token.should_not == nil
20
- @gs.comm_token.should match /^[abcdef\d]{13}$/i
20
+ @gs.comm_token.should match /^[abcdef\d]{40}$/i
21
21
  end
22
22
  end
23
23
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grooveshark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Sosedoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-18 00:00:00.000000000 Z
11
+ date: 2013-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec