Class: Boxspring::Property

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Pictureable

#picture_by_code_name, #pictures

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Boxspring::Base

Class Method Details

.find_by(parameters) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/boxspring/property.rb', line 7

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
  request = Request.new( parameters )
  response = request.get( '/configuration' )

   # did the api request succeed
   if ( response.success? )
     # construct a property; assign it the api interface
     Property.new( response.content ).tap do | property |
       property.instance_variable_set( '@api_interface', request )
     end
   elsif ( response.code == '404' )
     nil
   else
     raise response.error
   end

end

Instance Method Details

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



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

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

#page_by_code_name(code_name) ⇒ Object



85
86
87
# File 'lib/boxspring/property.rb', line 85

def page_by_code_name( code_name )
  self.pages.detect { |page| page.code_name == code_name }
end

#page_by_id(id) ⇒ Object



89
90
91
92
93
94
95
96
97
98
# File 'lib/boxspring/property.rb', line 89

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

#pages(parameters = {}) ⇒ Object



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

def pages( parameters = {} )
  @pages ||= begin
    self.attributes.include?( :pages ) ?
      self.attributes[ :pages ].map do | page |
        Page.new( page )
      end :
      nil
  end
end

#reaction_by_id(id) ⇒ Object



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

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



71
72
73
# File 'lib/boxspring/property.rb', line 71

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

#servicesObject



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

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



121
122
123
124
125
126
127
128
129
130
# File 'lib/boxspring/property.rb', line 121

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

#showsObject



132
133
134
135
136
137
138
139
140
# File 'lib/boxspring/property.rb', line 132

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

#shows_stories(parameters = {}) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/boxspring/property.rb', line 177

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

#stories(parameters = {}) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/boxspring/property.rb', line 164

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

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



190
191
192
193
194
195
196
197
198
199
# File 'lib/boxspring/property.rb', line 190

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

#tag_by_id(id) ⇒ Object



110
111
112
113
114
115
116
117
118
119
# File 'lib/boxspring/property.rb', line 110

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



100
101
102
103
104
105
106
107
108
# File 'lib/boxspring/property.rb', line 100

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

#themeObject



53
54
55
56
57
58
59
# File 'lib/boxspring/property.rb', line 53

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