Class: Boxspring::Property

Inherits:
Base
  • Object
show all
Defined in:
lib/boxspring/property.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Boxspring::Base

Class Method Details

.find_by(parameters) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/boxspring/property.rb', line 5

def self.find_by( parameters )

   # filter only acceptable parameters
   parameters = parameters.stringify_keys.slice(
     'code_name', 'domain_name'
   )

   # translate attribute names to property identification paramaters
   parameters[ 'property_code' ] = parameters.delete( 'code_name' ) \
     if parameters.include?( 'code_name' )
   parameters[ 'property_domain_name' ] = parameters.delete( 'domain_name' ) \
     if parameters.include?( 'domain_name' )

   # create and make the request; raise an error if one occurs
  request = Request.new( parameters )
  response = request.get( '/configuration' )
  raise response.error if response.failure?

   # construct a property; retain the request an apu interface
  Property.new( response.content ).tap do | property |
    property.instance_variable_set( '@api_interface', request )
  end

end

Instance Method Details

#attribution_by_id(id, parameters = {}) ⇒ Object



105
106
107
108
109
110
111
112
113
114
# File 'lib/boxspring/property.rb', line 105

def attribution_by_id( id, parameters = {} )
  response = @api_interface.get( "/attributions/#{id}", parameters )
  if ( response.success? )
    Attribution.new( response.content )
  elsif ( response.code == '404' )
    nil
  else
    raise response.error
  end
end

#reaction_by_id(id) ⇒ Object



116
117
118
119
120
121
122
123
124
125
# File 'lib/boxspring/property.rb', line 116

def reaction_by_id( id )
  response = @api_interface.get( "/reactions/#{id}" )
  if ( response.success? )
    Reaction.new( response.content )
  elsif ( response.code == '404' )
    nil
  else
    raise response.error
  end
end

#service_by_provider(provider) ⇒ Object



59
60
61
# File 'lib/boxspring/property.rb', line 59

def service_by_provider( provider )
  self.services.detect { |service| service.provider == provider }
end

#services ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/boxspring/property.rb', line 49

def services
  @_services ||= begin
    self.attributes.include?( :services ) ?
      self.attributes[ :services ].map do | service |
        Service.new( service )
      end :
      nil
  end
end

#show_by_id(id) ⇒ Object



84
85
86
87
88
89
90
91
92
93
# File 'lib/boxspring/property.rb', line 84

def show_by_id( id )
  response = @api_interface.get( "/shows/#{id}" )
  if ( response.success? )
    Show.new( response.content )
  elsif ( response.code == '404' )
    nil
  else
    raise response.error
  end
end

#shows ⇒ Object



95
96
97
98
99
100
101
102
103
# File 'lib/boxspring/property.rb', line 95

def shows
  @_shows ||= begin
    self.attributes.include?( :shows ) ?
      self.attributes[ :shows ].map do | show |
        Show.new( show )
      end :
      nil
  end
end

#shows_videos(parameters = {}) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/boxspring/property.rb', line 140

def shows_videos( parameters = {} )
  response = @api_interface.get( "/shows/videos", parameters )
  if ( response.success? )
    response.content.map do | video |
      Video.new( video )
    end
  elsif ( response.code == '404' )
    nil
  else
    raise response.error
  end
end

#tag_by_id(id) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/boxspring/property.rb', line 73

def tag_by_id( id )
  response = @api_interface.get( "/tags/#{id}" )
  if ( response.success? )
    Tag.new( response.content )
  elsif ( response.code == '404' )
    nil
  else
    raise response.error
  end
end

#tag_collections(reload = false) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/boxspring/property.rb', line 63

def tag_collections( reload = false )
  @_tag_collections ||= begin
    self.attributes.include?( :tag_collections ) ?
      self.attributes[ :tag_collections ].map do | tag_collection |
        TagCollection.new( tag_collection )
      end :
      nil
  end
end

#theme ⇒ Object



41
42
43
44
45
46
47
# File 'lib/boxspring/property.rb', line 41

def theme
  @_theme ||= begin
    self.attributes.include?( :theme ) ?
      Theme.new( self.attributes[ :theme ] ) :
      nil
  end
end

#video_by_id(id) ⇒ Object



153
154
155
156
157
158
159
160
161
162
# File 'lib/boxspring/property.rb', line 153

def video_by_id( id )
  response = @api_interface.get( "/videos/#{id}" )
  if ( response.success? )
    Video.new( response.content )
  elsif ( response.code == '404' )
    nil
  else
    raise response.error
  end
end

#videos(parameters = {}) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/boxspring/property.rb', line 127

def videos( parameters = {} )
  response = @api_interface.get( "/videos", parameters )
  if ( response.success? )
    response.content.map do | video |
      Video.new( video )
    end
  elsif ( response.code == '404' )
    nil
  else
    raise response.error
  end
end