music_xray_api 0.0.1 → 0.1.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/README.rdoc +10 -31
- data/VERSION +1 -1
- data/lib/music_xray_api.rb +9 -5
- data/lib/music_xray_api/base.rb +76 -14
- data/lib/music_xray_api/track.rb +8 -0
- data/lib/music_xray_api/track_match_request.rb +8 -0
- data/lib/music_xray_api/track_set.rb +7 -0
- data/lib/music_xray_api/track_set_member.rb +7 -0
- data/music_xray_api.gemspec +52 -0
- data/test/helper.rb +3 -1
- data/test/test_music_xray_api.rb +34 -6
- metadata +7 -3
- data/lib/music_xray_api/tracks.rb +0 -14
data/README.rdoc
CHANGED
@@ -1,47 +1,26 @@
|
|
1
|
-
=
|
1
|
+
= music_xray_api
|
2
2
|
|
3
3
|
Really simple gem that allows you to send email through amazon simple email
|
4
4
|
service.
|
5
5
|
|
6
6
|
<b>Installation</b>
|
7
7
|
|
8
|
-
gem install
|
8
|
+
gem install music_xray_api
|
9
9
|
|
10
10
|
<b>Usage:</b>
|
11
11
|
|
12
12
|
require 'rubygems'
|
13
|
-
require '
|
13
|
+
require 'music_xray_api'
|
14
14
|
|
15
15
|
# all methods return a raw http response object
|
16
|
-
# to get the
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
16
|
+
# to get the return bundle just call body...
|
17
|
+
# at some point we may have methods for making things a bit prettier
|
18
|
+
# Please try not to abuse the api. We take steps to make it scale, however you should limit your rate to
|
19
|
+
# about 10 requests/second. Anything more than this may be seen as excessive and you may be banned.
|
20
|
+
|
21
|
+
Please click into the various classes for more detailed documentation and usage example.
|
22
|
+
|
20
23
|
|
21
|
-
|
22
|
-
# you must have a verified address with amazon to send mail
|
23
|
-
AmazonSES::Verify.address("youremail@gmail.com",amazon_secret,amazon_key)
|
24
|
-
|
25
|
-
# after verifying the address you can send mail
|
26
|
-
|
27
|
-
# simple send mail text only
|
28
|
-
AmazonSES::AmzMail.send(from,to,subject,body,secret,key)
|
29
|
-
# send html email
|
30
|
-
AmazonSES::AmzMail.send_html(from,to,subject,body,secret,key)
|
31
|
-
# if you produce your own email via the mail gem you can pass the result of calling to_s on the mail object
|
32
|
-
# to the following method
|
33
|
-
AmazonSES::AmzMail.send_raw(mail_string,amazon_secret,amazon_key)
|
34
|
-
|
35
|
-
# the following are two methods for getting stats
|
36
|
-
|
37
|
-
puts AmazonSES::Stats.send_quota(amazon_secret,amazon_key).body
|
38
|
-
puts AmazonSES::Stats.send_stats(amazon_secret,amazon_key).body
|
39
|
-
|
40
|
-
# the following is a helper object for looking at your stats
|
41
|
-
|
42
|
-
stobj = StatObject.new(amazon_secret,amazon_key)
|
43
|
-
puts stobj.sent_last_24_hours
|
44
|
-
puts stobj.reached_quota?
|
45
24
|
|
46
25
|
|
47
26
|
Hope you enjoy the Gem. If anyone wants to write a plugin for rails I would link definately link to it and find it useful.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/lib/music_xray_api.rb
CHANGED
@@ -6,11 +6,15 @@ require "base64"
|
|
6
6
|
require "openssl"
|
7
7
|
require "digest/sha1"
|
8
8
|
require "rubygems"
|
9
|
-
require "mail"
|
10
|
-
require "xmlsimple"
|
9
|
+
#require "mail"
|
10
|
+
#require "xmlsimple"
|
11
|
+
require 'active_resource'
|
12
|
+
|
11
13
|
|
12
14
|
$:.unshift(File.dirname(__FILE__))
|
13
15
|
require 'music_xray_api/base'
|
14
|
-
require 'music_xray_api/
|
15
|
-
|
16
|
-
|
16
|
+
require 'music_xray_api/track'
|
17
|
+
require 'music_xray_api/track_set'
|
18
|
+
require 'music_xray_api/track_set_member'
|
19
|
+
require 'music_xray_api/track_match_request'
|
20
|
+
|
data/lib/music_xray_api/base.rb
CHANGED
@@ -1,33 +1,95 @@
|
|
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
|
+
|
1
22
|
module MusicXrayApi
|
23
|
+
|
2
24
|
class Base
|
3
|
-
|
25
|
+
@@key ||= ""
|
26
|
+
@@secret ||= ""
|
27
|
+
|
28
|
+
def self.key= k
|
29
|
+
@@key = k
|
30
|
+
end
|
31
|
+
def self.secret= s
|
32
|
+
@@secret = s
|
33
|
+
end
|
4
34
|
def self.rfc2616(time)
|
5
35
|
time.utc.strftime("%a, %d %b %Y %H:%M:%S")+" +0000"
|
6
36
|
end
|
7
37
|
def self.sign_https_request(request,date,secret,key)
|
8
38
|
return "{'client_key_id':'#{key}', 'algorithm':'HmacSHA256', 'signature':'#{Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new("sha256"), secret, date)).strip}'}"
|
9
39
|
end
|
10
|
-
def self.
|
40
|
+
def self.sign_https_requestv3(date)
|
41
|
+
return "{'client_key_id':'#{@@key}', 'algorithm':'HmacSHA256', 'signature':'#{Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new("sha256"), @@secret, date)).strip}'}"
|
42
|
+
end
|
43
|
+
def self.make_request(secret,key,postfix,form_hash,method)
|
11
44
|
date = MusicXrayApi::Base.rfc2616(Time.now)
|
12
|
-
uri = URI.parse("https://api
|
45
|
+
uri = URI.parse("https://api.musicxray.com/#{postfix}.xml")
|
13
46
|
http = Net::HTTP.new(uri.host, uri.port)
|
14
47
|
http.use_ssl = true
|
15
48
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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)
|
23
65
|
case response
|
24
66
|
when Net::HTTPSuccess then return response
|
25
|
-
when Net::HTTPClientError then raise response.body
|
26
|
-
when Net::HTTPServerError then raise response.body
|
27
|
-
else raise response.body
|
67
|
+
when Net::HTTPClientError then raise "#{response.body}"
|
68
|
+
when Net::HTTPServerError then raise "#{response.body}"
|
69
|
+
else raise "#{response.body}"
|
28
70
|
end
|
29
71
|
#return response
|
30
72
|
end
|
31
|
-
|
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
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
module ResourceMethods
|
84
|
+
def self.included(klass)
|
85
|
+
klass.extend ClassMethods
|
86
|
+
end
|
87
|
+
module ClassMethods
|
88
|
+
def set_headers
|
89
|
+
self.site = 'https://api.musicxray.com'
|
90
|
+
date = MusicXrayApi::Base.rfc2616(Time.now)
|
91
|
+
headers['Date'] = date.to_s
|
92
|
+
headers['X-Xray-Authorization'] = MusicXrayApi::Base.sign_https_requestv3(date)
|
93
|
+
end
|
32
94
|
end
|
33
95
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{music_xray_api}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["jeff durand"]
|
12
|
+
s.date = %q{2011-05-18}
|
13
|
+
s.description = %q{wrapper for music xray api }
|
14
|
+
s.email = %q{jeff.durand@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"lib/music_xray_api.rb",
|
26
|
+
"lib/music_xray_api/base.rb",
|
27
|
+
"lib/music_xray_api/track.rb",
|
28
|
+
"lib/music_xray_api/track_match_request.rb",
|
29
|
+
"lib/music_xray_api/track_set.rb",
|
30
|
+
"lib/music_xray_api/track_set_member.rb",
|
31
|
+
"music_xray_api.gemspec",
|
32
|
+
"test/helper.rb",
|
33
|
+
"test/test_music_xray_api.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/johnnyiller/Music-Xray-Api-Wrapper}
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.7.2}
|
38
|
+
s.summary = %q{Interface with the music xray api}
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_runtime_dependency(%q<xml-simple>, [">= 0"])
|
45
|
+
else
|
46
|
+
s.add_dependency(%q<xml-simple>, [">= 0"])
|
47
|
+
end
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<xml-simple>, [">= 0"])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
data/test/helper.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'test/unit'
|
3
3
|
require 'shoulda'
|
4
|
-
|
4
|
+
require 'yaml'
|
5
5
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
6
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
+
|
8
|
+
|
7
9
|
require 'music_xray_api'
|
8
10
|
|
9
11
|
class Test::Unit::TestCase
|
data/test/test_music_xray_api.rb
CHANGED
@@ -1,18 +1,46 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
+
|
3
4
|
class TestMusicXrayApi < Test::Unit::TestCase
|
4
5
|
context "Has valid credentials" do
|
5
6
|
setup do
|
6
7
|
YAML.load_file("./test/credentials.yml").each { |key,value| instance_variable_set("@#{key}", value) }
|
8
|
+
MusicXrayApi::Base.key = @key
|
9
|
+
MusicXrayApi::Base.secret = @secret
|
10
|
+
MusicXrayApi::Track.set_headers
|
11
|
+
MusicXrayApi::TrackSet.set_headers
|
12
|
+
MusicXrayApi::TrackSetMember.set_headers
|
13
|
+
MusicXrayApi::TrackMatchRequest.set_headers
|
14
|
+
|
7
15
|
end
|
8
16
|
should "Be able to create a track." do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
17
|
+
tr = MusicXrayApi::Track.create({:mp3_url=>"http://www.google.com", :uri=>"xray/#{Time.now.to_i.to_s}"})
|
18
|
+
puts tr.id
|
19
|
+
end
|
20
|
+
should "be able to do crud for track sets" do
|
21
|
+
ts = MusicXrayApi::TrackSet.new
|
22
|
+
ts.name = "another my new one"
|
23
|
+
puts ts.save
|
24
|
+
puts ts.id
|
25
|
+
unless ts
|
26
|
+
ts.errors
|
14
27
|
end
|
15
|
-
|
28
|
+
fts = MusicXrayApi::TrackSet.find(ts.id)
|
29
|
+
puts fts.name
|
30
|
+
end
|
31
|
+
should "be able to add a track I create to a track set I also create" do
|
32
|
+
t1 = MusicXrayApi::Track.create({:mp3_url=>"http://www.google.com", :uri=>"xray/#{Time.now.to_i.to_s}1"})
|
33
|
+
t2 = MusicXrayApi::Track.create({:mp3_url=>"http://www.google.com", :uri=>"xray/#{Time.now.to_i.to_s}2"})
|
34
|
+
t3 = MusicXrayApi::Track.create({:mp3_url=>"http://www.google.com", :uri=>"xray/#{Time.now.to_i.to_s}3"})
|
35
|
+
ts = MusicXrayApi::TrackSet.create({:name=>"whatever it's just a name"})
|
36
|
+
tsm = MusicXrayApi::TrackSetMember.create({:track_id=>t1.id, :track_set_id=>ts.id})
|
37
|
+
tsm = MusicXrayApi::TrackSetMember.create({:track_id=>t2.id, :track_set_id=>ts.id})
|
38
|
+
# testing matching request capable
|
39
|
+
tmr = MusicXrayApi::TrackMatchRequest.create({:track_id=>t3.id, :track_set_id=>ts.id,:result_delivery_method=>'none'})
|
40
|
+
|
16
41
|
end
|
42
|
+
|
17
43
|
end
|
18
44
|
end
|
45
|
+
|
46
|
+
|
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.0
|
5
|
+
version: 0.1.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: 2011-05-
|
13
|
+
date: 2011-05-18 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: xml-simple
|
@@ -40,7 +40,11 @@ files:
|
|
40
40
|
- VERSION
|
41
41
|
- lib/music_xray_api.rb
|
42
42
|
- lib/music_xray_api/base.rb
|
43
|
-
- lib/music_xray_api/
|
43
|
+
- lib/music_xray_api/track.rb
|
44
|
+
- lib/music_xray_api/track_match_request.rb
|
45
|
+
- lib/music_xray_api/track_set.rb
|
46
|
+
- lib/music_xray_api/track_set_member.rb
|
47
|
+
- music_xray_api.gemspec
|
44
48
|
- test/helper.rb
|
45
49
|
- test/test_music_xray_api.rb
|
46
50
|
homepage: http://github.com/johnnyiller/Music-Xray-Api-Wrapper
|