music_xray_api 0.1.0 → 0.2.0
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.
- data/VERSION +1 -1
- data/lib/music_xray_api/base.rb +8 -60
- data/lib/music_xray_api.rb +5 -1
- data/music_xray_api.gemspec +8 -8
- data/test/test_music_xray_api.rb +92 -26
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/music_xray_api/base.rb
CHANGED
@@ -1,24 +1,3 @@
|
|
1
|
-
class Hash
|
2
|
-
def to_url_params
|
3
|
-
elements = []
|
4
|
-
keys.size.times do |i|
|
5
|
-
elements << "#{CGI::escape(keys[i])}=#{CGI::escape(values[i])}"
|
6
|
-
end
|
7
|
-
elements.join('&')
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.from_url_params(url_params)
|
11
|
-
result = {}.with_indifferent_access
|
12
|
-
url_params.split('&').each do |element|
|
13
|
-
element = element.split('=')
|
14
|
-
result[element[0]] = element[1]
|
15
|
-
end
|
16
|
-
result
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
1
|
module MusicXrayApi
|
23
2
|
|
24
3
|
class Base
|
@@ -31,6 +10,12 @@ module MusicXrayApi
|
|
31
10
|
def self.secret= s
|
32
11
|
@@secret = s
|
33
12
|
end
|
13
|
+
def self.api_endpoint= apiend
|
14
|
+
@@api_endpoint = apiend
|
15
|
+
end
|
16
|
+
def self.api_endpoint
|
17
|
+
return @@api_endpoint
|
18
|
+
end
|
34
19
|
def self.rfc2616(time)
|
35
20
|
time.utc.strftime("%a, %d %b %Y %H:%M:%S")+" +0000"
|
36
21
|
end
|
@@ -40,53 +25,16 @@ module MusicXrayApi
|
|
40
25
|
def self.sign_https_requestv3(date)
|
41
26
|
return "{'client_key_id':'#{@@key}', 'algorithm':'HmacSHA256', 'signature':'#{Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new("sha256"), @@secret, date)).strip}'}"
|
42
27
|
end
|
43
|
-
def self.make_request(secret,key,postfix,form_hash,method)
|
44
|
-
date = MusicXrayApi::Base.rfc2616(Time.now)
|
45
|
-
uri = URI.parse("https://api.musicxray.com/#{postfix}.xml")
|
46
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
47
|
-
http.use_ssl = true
|
48
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
49
|
-
if method.to_s.downcase=="post"
|
50
|
-
@request = Net::HTTP::Post.new(uri.request_uri)
|
51
|
-
@request.set_form_data(form_hash)
|
52
|
-
@request['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8'
|
53
|
-
elsif method.to_s.downcase=="get"
|
54
|
-
@request = Net::HTTP::Get.new("#{uri.request_uri}?#{form_hash.to_url_params}")
|
55
|
-
elsif method.to_s.downcase=="put"
|
56
|
-
@request = Net::HTTP::Put.new(uri.request_uri)
|
57
|
-
@request.set_form_data(form_hash)
|
58
|
-
@request['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8'
|
59
|
-
elsif method.to_s.downcase=="delete"
|
60
|
-
@request = Net::HTTP::Delete.new("#{uri.request_uri}?#{form_hash.to_url_params}")
|
61
|
-
end
|
62
|
-
@request.add_field("Date",date)
|
63
|
-
@request.add_field("X-Xray-Authorization",MusicXrayApi::Base.sign_https_request(@request,date,secret,key))
|
64
|
-
response = http.request(@request)
|
65
|
-
case response
|
66
|
-
when Net::HTTPSuccess then return response
|
67
|
-
when Net::HTTPClientError then raise "#{response.body}"
|
68
|
-
when Net::HTTPServerError then raise "#{response.body}"
|
69
|
-
else raise "#{response.body}"
|
70
|
-
end
|
71
|
-
#return response
|
72
|
-
end
|
73
|
-
def self.objectify_params(outer,params)
|
74
|
-
nar = {}
|
75
|
-
params.each do |key,value|
|
76
|
-
nar["#{outer}[#{key}]"]=value
|
77
|
-
end
|
78
|
-
return nar
|
79
|
-
end
|
80
28
|
end
|
81
29
|
end
|
82
|
-
|
83
30
|
module ResourceMethods
|
84
31
|
def self.included(klass)
|
85
32
|
klass.extend ClassMethods
|
86
33
|
end
|
87
34
|
module ClassMethods
|
88
35
|
def set_headers
|
89
|
-
self.site =
|
36
|
+
self.site = MusicXrayApi::Base.api_endpoint
|
37
|
+
self.format = :xml
|
90
38
|
date = MusicXrayApi::Base.rfc2616(Time.now)
|
91
39
|
headers['Date'] = date.to_s
|
92
40
|
headers['X-Xray-Authorization'] = MusicXrayApi::Base.sign_https_requestv3(date)
|
data/lib/music_xray_api.rb
CHANGED
@@ -8,7 +8,11 @@ require "digest/sha1"
|
|
8
8
|
require "rubygems"
|
9
9
|
#require "mail"
|
10
10
|
#require "xmlsimple"
|
11
|
-
|
11
|
+
#gem 'activesupport', '2.3.5'
|
12
|
+
#gem 'activeresource', '2.3.5'
|
13
|
+
#require 'activesupport'
|
14
|
+
require 'activeresource'
|
15
|
+
|
12
16
|
|
13
17
|
|
14
18
|
$:.unshift(File.dirname(__FILE__))
|
data/music_xray_api.gemspec
CHANGED
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.
|
7
|
+
s.name = "music_xray_api"
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["jeff durand"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2012-05-02"
|
13
|
+
s.description = "wrapper for music xray api "
|
14
|
+
s.email = "jeff.durand@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
17
|
"README.rdoc"
|
@@ -32,10 +32,10 @@ Gem::Specification.new do |s|
|
|
32
32
|
"test/helper.rb",
|
33
33
|
"test/test_music_xray_api.rb"
|
34
34
|
]
|
35
|
-
s.homepage =
|
35
|
+
s.homepage = "http://github.com/johnnyiller/Music-Xray-Api-Wrapper"
|
36
36
|
s.require_paths = ["lib"]
|
37
|
-
s.rubygems_version =
|
38
|
-
s.summary =
|
37
|
+
s.rubygems_version = "1.8.23"
|
38
|
+
s.summary = "Interface with the music xray api"
|
39
39
|
|
40
40
|
if s.respond_to? :specification_version then
|
41
41
|
s.specification_version = 3
|
data/test/test_music_xray_api.rb
CHANGED
@@ -7,39 +7,105 @@ class TestMusicXrayApi < Test::Unit::TestCase
|
|
7
7
|
YAML.load_file("./test/credentials.yml").each { |key,value| instance_variable_set("@#{key}", value) }
|
8
8
|
MusicXrayApi::Base.key = @key
|
9
9
|
MusicXrayApi::Base.secret = @secret
|
10
|
+
MusicXrayApi::Base.api_endpoint = @endpoint
|
10
11
|
MusicXrayApi::Track.set_headers
|
11
12
|
MusicXrayApi::TrackSet.set_headers
|
12
13
|
MusicXrayApi::TrackSetMember.set_headers
|
13
14
|
MusicXrayApi::TrackMatchRequest.set_headers
|
14
15
|
|
15
16
|
end
|
16
|
-
should "
|
17
|
-
|
18
|
-
puts
|
17
|
+
should "Find some cached tracks" do
|
18
|
+
params = {:application_name=>"present",:application_id=>"246458"}
|
19
|
+
puts MusicXrayApi::Track.find(:all,:params=>params).first.inspect
|
19
20
|
end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
ts.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
21
|
+
#
|
22
|
+
# should "Be able to create a track." do
|
23
|
+
# tr = MusicXrayApi::Track.create({:mp3_url=>"http://www.google.com", :uri=>"xray/#{Time.now.to_i.to_s}"})
|
24
|
+
# puts tr.id
|
25
|
+
# end
|
26
|
+
# should "be able to do crud for track sets" do
|
27
|
+
# ts = MusicXrayApi::TrackSet.new
|
28
|
+
# ts.name = "another my new one"
|
29
|
+
# puts ts.save
|
30
|
+
# puts ts.id
|
31
|
+
# unless ts
|
32
|
+
# ts.errors
|
33
|
+
# end
|
34
|
+
# fts = MusicXrayApi::TrackSet.find(ts.id)
|
35
|
+
# #fts.destroy
|
36
|
+
# puts fts.name
|
37
|
+
# end
|
38
|
+
# should "be able to add a track I create to a track set I also create" do
|
39
|
+
# turi1 = "xray/#{Time.now.to_i.to_s}1"
|
40
|
+
# turi2 = "xray/#{Time.now.to_i.to_s}2"
|
41
|
+
# turi3 = "xray/#{Time.now.to_i.to_s}3"
|
42
|
+
# ids = [turi1,turi2]
|
43
|
+
# t1 = MusicXrayApi::Track.create({:mp3_url=>"http://www.google.com", :uri=>turi1})
|
44
|
+
# t2 = MusicXrayApi::Track.create({:mp3_url=>"http://www.google.com", :uri=>turi2})
|
45
|
+
# t3 = MusicXrayApi::Track.create({:mp3_url=>"http://www.google.com", :uri=>turi3})
|
46
|
+
# ts = MusicXrayApi::TrackSet.create({:name=>"whatever it's just a name"})
|
47
|
+
# tsm = MusicXrayApi::TrackSetMember.create({:track_id=>t1.id, :track_set_id=>ts.id})
|
48
|
+
# tsm = MusicXrayApi::TrackSetMember.create({:track_id=>t2.id, :track_set_id=>ts.id})
|
49
|
+
# # testing matching request capable
|
50
|
+
# tmr = MusicXrayApi::TrackMatchRequest.create({:track_id=>t3.id, :track_set_id=>ts.id,:result_delivery_method=>'none'})
|
51
|
+
# #puts tsm.inspect
|
52
|
+
# tsm.destroy
|
53
|
+
# puts ids.inspect
|
54
|
+
# tracks = MusicXrayApi::Track.find :all, :params=>{:uris=>ids.join(",")}
|
55
|
+
# puts tracks.inspect
|
56
|
+
# end
|
57
|
+
# should "be able to update a track causing it to re-index" do
|
58
|
+
# t = MusicXrayApi::Track.find :all
|
59
|
+
# #puts t.inspect
|
60
|
+
# f = t.first
|
61
|
+
# f.recalcfeatures = true
|
62
|
+
# f.save
|
63
|
+
# f.reload
|
64
|
+
# puts f.inspect
|
65
|
+
# end
|
66
|
+
#
|
67
|
+
# should "be able to find all tracks that aren't extracted" do
|
68
|
+
# @page = 0
|
69
|
+
# #puts MusicXrayApi::Track.find(:all, params=>{:page=>@page}).inspect
|
70
|
+
# #while(tracks = MusicXrayApi::Track.find(:all, :params=>{:page=>@page, :extracted=>false})) do
|
71
|
+
# # puts @page
|
72
|
+
# # puts "found #{tracks.size} tracks"
|
73
|
+
# # if tracks.size <= 0
|
74
|
+
# # break
|
75
|
+
# # end
|
76
|
+
# # puts tracks.first.id
|
77
|
+
# # puts tracks.last.id
|
78
|
+
# #tracks.each do |t|
|
79
|
+
# # puts t.id
|
80
|
+
# #end
|
81
|
+
# #tracks = nil
|
82
|
+
# # @page +=1
|
83
|
+
# #end
|
84
|
+
#
|
85
|
+
# #while(track_match_requests = MusicXrayApi::TrackMatchRequest.find(:all,:params=>{:page=>@page,:limit=>50})) do
|
86
|
+
# # puts @page
|
87
|
+
# # puts "found matches #{track_match_requests.size}"
|
88
|
+
# # if track_match_requests.size <= 0
|
89
|
+
# # break
|
90
|
+
# # end
|
91
|
+
# # puts track_match_requests.first.id
|
92
|
+
# # puts track_match_requests.last.id
|
93
|
+
# # @page+=1
|
94
|
+
# #end
|
95
|
+
# #@trm = MusicXrayApi::TrackMatchRequest.find(:all,:params=>{:limit=>1}).first
|
96
|
+
# #@trm.put(:rematch)
|
97
|
+
# #@trm.inspect
|
98
|
+
# end
|
99
|
+
# should "be able to create track and find it later" do
|
100
|
+
# # time = Time.now.to_i.to_s
|
101
|
+
# # t1 = MusicXrayApi::Track.create({:mp3_url=>"http://www.google.com",
|
102
|
+
# # :uri=>"xray/#{Time.now.to_i.to_s}12",
|
103
|
+
# # :application_name=>'myxrays',
|
104
|
+
# # :application_id=>"#{time}"})
|
105
|
+
# #puts t1.inspect
|
106
|
+
# # tracks = MusicXrayApi::Track.find :all, :params=>{:application_name=>'myxrays', :application_id=>time}
|
107
|
+
#
|
108
|
+
# end
|
43
109
|
end
|
44
110
|
end
|
45
111
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: music_xray_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- jeff durand
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2012-05-02 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: xml-simple
|
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
requirements: []
|
71
71
|
|
72
72
|
rubyforge_project:
|
73
|
-
rubygems_version: 1.
|
73
|
+
rubygems_version: 1.8.23
|
74
74
|
signing_key:
|
75
75
|
specification_version: 3
|
76
76
|
summary: Interface with the music xray api
|