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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f3fdc60db02c8bbfa36023b732257ff4ae00065
4
- data.tar.gz: 941b8112fe6a9344ddfe55f9d12c21b241662437
3
+ metadata.gz: 043920c658cc312bec4202618892106d3be596b8
4
+ data.tar.gz: 42d9d244baaf31ae58b3dc2af50deddea4774363
5
5
  SHA512:
6
- metadata.gz: 235593bdfb705801839aeae291eb10099d587001a44a03355c03c29f3d3c0fcd12ed93b9d3188e85f73dbbabea2eccfa40c81dc78fe2fdb674448ce50f21088a
7
- data.tar.gz: d6386baee0d822ec72f8d58cf1c6aad21871bb64f26e307a00c2b1c9409b855451f326034ef1f9e08d319fbd3e0c275f4c5128423be5d7420f56c07ab47f6d8d
6
+ metadata.gz: c709964286027646fa394e024d25e4856db28efd5073215e7fd084b5dfaf4d518b58087a0cc246cfd9c1356aee0b56b7578b677c6eb903870f6e77cfe3c5b2c9
7
+ data.tar.gz: 01390ffa64aff696d8a6565580cad23a52e33f8cc805c74d5c938f048ba4571796314051abacc226cb8dd35a180b16eee5d6904ce7a91c2cd401dc736fe5e325
@@ -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
- block.call(RestClient.get(url, :params => params), nil)
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(nil, e.response)
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
- block.call(RestClient.put(url, params), nil)
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
- block.call(RestClient.post(url, params), nil)
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(nil, e.response)
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
- block.call(RestClient.delete(url, params), nil)
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(nil, e.response)
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 :properties
3
+ attr_reader :_properties
4
4
 
5
5
  def initialize(properties={})
6
- @properties = properties
6
+ @_properties = properties
7
7
  end
8
8
 
9
9
  def method_missing(method, *args, &block)
10
- @properties[method.to_sym]
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
@@ -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
- objectize(object, parse_object(response[object]))
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
- return response.collect do |object|
22
- objectize(object['object'], parse_object(object))
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
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 00:00:00.000000000 Z
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