spotifiery 0.0.2 → 0.0.3

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.
@@ -11,7 +11,6 @@ module Spotifiery
11
11
  def initialize response, response_class = nil
12
12
 
13
13
  response_hash = HashWithIndifferentAccess.new response
14
-
15
14
  @info = response_hash[:info]
16
15
  response_results = response_hash[ ActiveSupport::Inflector.pluralize(@info[:type]) ]
17
16
  response_class = ActiveSupport::Inflector.constantize( "Spotifiery::Searchable::" + ActiveSupport::Inflector.titleize(@info[:type])) if response_class.blank?
@@ -23,7 +22,7 @@ module Spotifiery
23
22
  end
24
23
 
25
24
 
26
- def method_missing(method, *args, &block)
25
+ def method_missing(method, *args, &block)
27
26
  if defined?(@info) && @info.has_key?(method)
28
27
  @info[method]
29
28
  elsif defined?(@info) && method.eql?( ActiveSupport::Inflector.pluralize(@info[:type]).to_sym )
@@ -39,7 +39,7 @@ module Spotifiery
39
39
  # Can be initialized from a spotify uri or from an search result hash.
40
40
  # This way Spotify is not asked when initialized from a search result when name, popularity, etc are called
41
41
  def initialize spotify_uri_or_hash
42
-
42
+ @base_attributes = {}
43
43
  if spotify_uri_or_hash.is_a? Hash
44
44
  initialize_base_attributes_getters HashWithIndifferentAccess.new spotify_uri_or_hash
45
45
  @href = spotify_uri_or_hash['href']
@@ -58,24 +58,28 @@ module Spotifiery
58
58
 
59
59
  def method_missing(method, *args, &block)
60
60
 
61
+ # Try to find the method in base_attributes
62
+ res = get_from_base_attrs(method)
61
63
  # Looked in spotify before?
62
- if !defined?(@lookup_response)
63
- lookup_in_spotify
64
+ lookup_in_spotify if res.blank? && !defined?(@lookup_response)
65
+ res = get_from_base_attrs(method)
66
+ if res.blank?
67
+ # If not try to see if an instance variable is defined
68
+ if instance_variable_defined?("@#{method}")
69
+ res = instance_variable_get("@#{method}")
70
+ else
71
+ super
72
+ end
64
73
  end
74
+ res
75
+ end
65
76
 
66
- # Try to find the method in base_attributes
67
- if @base_attributes.has_key? method
68
- # Always try to parse for integers
69
- Integer(@base_attributes[method],10) rescue @base_attributes[method]
70
- # If not try to see if an instance variable is defined
71
- elsif instance_variable_defined?("@#{method}")
72
- instance_variable_get("@#{method}")
73
- else
74
- super
75
- end
76
77
 
78
+ def get_from_base_attrs(method)
79
+ Integer(@base_attributes[method],10) rescue @base_attributes[method]
77
80
  end
78
81
 
82
+
79
83
  def respond_to_missing?(method, include_private = false)
80
84
  if !defined? @lookup_response
81
85
  lookup_in_spotify
@@ -137,7 +141,7 @@ module Spotifiery
137
141
  def define_base_method method
138
142
  send(:define_singleton_method, method) do
139
143
  # Always try to parse for integers
140
- Integer(@base_attributes[attribute],10) rescue @base_attributes[attribute]
144
+ get_from_base_attrs(method)
141
145
  end
142
146
  end
143
147
 
@@ -1,3 +1,3 @@
1
1
  module Spotifiery
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spotifiery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-02 00:00:00.000000000 Z
12
+ date: 2013-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty