songdrop 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/songdrop/client.rb +10 -10
- data/lib/songdrop/http/rest-client.rb +12 -8
- data/lib/songdrop/objects/base.rb +6 -3
- data/lib/songdrop/objects/collection.rb +18 -0
- data/lib/songdrop/parser.rb +13 -4
- data/lib/songdrop.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 043920c658cc312bec4202618892106d3be596b8
|
4
|
+
data.tar.gz: 42d9d244baaf31ae58b3dc2af50deddea4774363
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c709964286027646fa394e024d25e4856db28efd5073215e7fd084b5dfaf4d518b58087a0cc246cfd9c1356aee0b56b7578b677c6eb903870f6e77cfe3c5b2c9
|
7
|
+
data.tar.gz: 01390ffa64aff696d8a6565580cad23a52e33f8cc805c74d5c938f048ba4571796314051abacc226cb8dd35a180b16eee5d6904ce7a91c2cd401dc736fe5e325
|
data/lib/songdrop/client.rb
CHANGED
@@ -11,32 +11,32 @@ module Songdrop
|
|
11
11
|
def get(path, params={}, &block)
|
12
12
|
puts "[Songdrop::Client] GET #{path} with #{params.inspect} block? #{block_given?}"
|
13
13
|
params.merge!(:client => @token, :token => @auth_token)
|
14
|
-
HTTP.get(full_url(path), params) do |response, error|
|
15
|
-
handle_response(response, error, &block)
|
14
|
+
HTTP.get(full_url(path), params) do |response, headers, error|
|
15
|
+
handle_response(response, headers, error, &block)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
def put(path, params={}, &block)
|
20
20
|
puts "[Songdrop::Client] PUT #{path} with #{params.inspect} block? #{block_given?}"
|
21
21
|
params.merge!(:client => @token, :token => @auth_token)
|
22
|
-
HTTP.put(full_url(path), params) do |response, error|
|
23
|
-
handle_response(response, error, &block)
|
22
|
+
HTTP.put(full_url(path), params) do |response, headers, error|
|
23
|
+
handle_response(response, headers, error, &block)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
def post(path, params={}, &block)
|
28
28
|
puts "[Songdrop::Client] POST #{path} with #{params.inspect} block? #{block_given?}"
|
29
29
|
params.merge!(:client => @token, :token => @auth_token)
|
30
|
-
HTTP.post(full_url(path), params) do |response, error|
|
31
|
-
handle_response(response, error, &block)
|
30
|
+
HTTP.post(full_url(path), params) do |response, headers, error|
|
31
|
+
handle_response(response, headers, error, &block)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
def delete(path, params={}, &block)
|
36
36
|
puts "[Songdrop::Client] DELETE #{path} with #{params.inspect} block? #{block_given?}"
|
37
37
|
params.merge!(:client => @token, :token => @auth_token)
|
38
|
-
HTTP.delete(full_url(path), params) do |response, error|
|
39
|
-
handle_response(response, error, &block)
|
38
|
+
HTTP.delete(full_url(path), params) do |response, headers, error|
|
39
|
+
handle_response(response, headers, error, &block)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -45,11 +45,11 @@ module Songdrop
|
|
45
45
|
"#{@endpoint}#{path}"
|
46
46
|
end
|
47
47
|
|
48
|
-
def handle_response(response, error, &block)
|
48
|
+
def handle_response(response, headers, error, &block)
|
49
49
|
target = response || error
|
50
50
|
res = nil
|
51
51
|
JSON.parse(target) do |obj|
|
52
|
-
res = Parser.parse(obj)
|
52
|
+
res = Parser.parse(obj, headers)
|
53
53
|
res = res.first if res.is_a? Array and res.size == 1
|
54
54
|
block.call res if block
|
55
55
|
res
|
@@ -3,37 +3,41 @@ module Songdrop
|
|
3
3
|
|
4
4
|
def self.get(url, params={}, &block)
|
5
5
|
begin
|
6
|
-
|
6
|
+
response = RestClient.get(url, :params => params)
|
7
|
+
block.call response, response.headers, nil
|
7
8
|
rescue => e
|
8
9
|
puts "[Songdrop::HTTP] Error: #{e.inspect}"
|
9
|
-
block.call
|
10
|
+
block.call nil, e.response.headers, e.response
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
14
|
def self.put(url, params={}, &block)
|
14
15
|
begin
|
15
|
-
|
16
|
+
response = RestClient.put(url, params)
|
17
|
+
block.call response, response.headers, nil
|
16
18
|
rescue => e
|
17
19
|
puts "[Songdrop::HTTP] Error: #{e.inspect}"
|
18
|
-
block.call nil, e.response
|
20
|
+
block.call nil, e.response.headers, e.response
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
24
|
def self.post(url, params={}, &block)
|
23
25
|
begin
|
24
|
-
|
26
|
+
response = RestClient.post(url, params)
|
27
|
+
block.call response, response.headers, nil
|
25
28
|
rescue => e
|
26
29
|
puts "[Songdrop::HTTP] Error: #{e.inspect}"
|
27
|
-
block.call
|
30
|
+
block.call nil, e.response.headers, e.response
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
31
34
|
def self.delete(url, params={}, &block)
|
32
35
|
begin
|
33
|
-
|
36
|
+
response = RestClient.delete(url, params)
|
37
|
+
block.call response, response.headers, nil
|
34
38
|
rescue => e
|
35
39
|
puts "[Songdrop::HTTP] Error: #{e.inspect}"
|
36
|
-
block.call
|
40
|
+
block.call nil, e.response.headers, e.response
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
@@ -1,13 +1,16 @@
|
|
1
1
|
module Songdrop
|
2
2
|
class Base
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :_properties
|
4
4
|
|
5
5
|
def initialize(properties={})
|
6
|
-
@
|
6
|
+
@_properties = properties
|
7
7
|
end
|
8
8
|
|
9
9
|
def method_missing(method, *args, &block)
|
10
|
-
|
10
|
+
method = $1 if method =~ /(\S+)\?/
|
11
|
+
method = method.to_sym
|
12
|
+
return @_properties[method] if @_properties.has_key?(method)
|
13
|
+
super
|
11
14
|
end
|
12
15
|
|
13
16
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Songdrop
|
2
|
+
class Collection < Array
|
3
|
+
attr_reader :_properties
|
4
|
+
|
5
|
+
def initialize(properties={})
|
6
|
+
@_properties = properties
|
7
|
+
end
|
8
|
+
|
9
|
+
def method_missing(method, *args, &block)
|
10
|
+
method = $1 if method =~ /(\S+)\?/
|
11
|
+
method = method.to_s
|
12
|
+
return @_properties[method] if @_properties.has_key?(method)
|
13
|
+
method = method.to_sym # super requires a symbol
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/lib/songdrop/parser.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Songdrop
|
2
2
|
class Parser
|
3
3
|
|
4
|
-
def self.parse(response)
|
4
|
+
def self.parse(response, headers={})
|
5
5
|
|
6
6
|
if response.is_a?(Hash) and response['object']
|
7
7
|
|
@@ -12,14 +12,23 @@ module Songdrop
|
|
12
12
|
|
13
13
|
# we got a hash pointer to objects
|
14
14
|
return response.keys.collect do |object|
|
15
|
-
|
15
|
+
objectize(object, parse_object(response[object]))
|
16
16
|
end
|
17
17
|
|
18
18
|
elsif response.is_a? Array
|
19
19
|
|
20
20
|
# we got an array of objects back
|
21
|
-
|
22
|
-
|
21
|
+
result = response.collect do |object|
|
22
|
+
properties = parse_object(object)
|
23
|
+
objectize(object['object'], properties)
|
24
|
+
end
|
25
|
+
|
26
|
+
if headers[:x_pagination]
|
27
|
+
collection = Collection.new(JSON.parse(headers[:x_pagination]))
|
28
|
+
collection.replace(result)
|
29
|
+
return collection
|
30
|
+
else
|
31
|
+
return result
|
23
32
|
end
|
24
33
|
|
25
34
|
else
|
data/lib/songdrop.rb
CHANGED
@@ -18,6 +18,7 @@ else
|
|
18
18
|
require_relative './songdrop/client'
|
19
19
|
require_relative './songdrop/client/methods'
|
20
20
|
require_relative './songdrop/objects/base'
|
21
|
+
require_relative './songdrop/objects/collection'
|
21
22
|
require_relative './songdrop/objects/image_helper'
|
22
23
|
require_relative './songdrop/objects/user'
|
23
24
|
require_relative './songdrop/objects/drop'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: songdrop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Taylor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: songdrop is a Ruby & RubyMotion client for the Songdrop.com API.
|
14
14
|
email: moomerman@gmail.com
|
@@ -28,6 +28,7 @@ files:
|
|
28
28
|
- lib/songdrop/json/json.rb
|
29
29
|
- lib/songdrop/objects/artist.rb
|
30
30
|
- lib/songdrop/objects/base.rb
|
31
|
+
- lib/songdrop/objects/collection.rb
|
31
32
|
- lib/songdrop/objects/drop.rb
|
32
33
|
- lib/songdrop/objects/error.rb
|
33
34
|
- lib/songdrop/objects/image_helper.rb
|