boxspring 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8cc9d3cfbbce05c4b5efe672a7b694189685af1b
4
+ data.tar.gz: a2ce99f4d150b42a5d6d6aed1a8a941cd2a03cb6
5
+ SHA512:
6
+ metadata.gz: 4853f2beffd0b9a8f410d6ba7a21b83dc5486da98f76ae8a3705942f72eee43762e041b04298e4dddc0faaa529d14deafc61177b7e8c4be58e96432d4951dcae
7
+ data.tar.gz: 51b8318aee2f792dde22f5f5f52d211dc13c53646732fa2332b114243ed421befb65a02cb65cacaddeebcbdab607898c6c9bb671f9629a7671446b6b47b4eae2
@@ -0,0 +1,16 @@
1
+ module Boxspring
2
+
3
+ class Attribution < Base
4
+
5
+ field :created_at
6
+ field :updated_at
7
+
8
+ field :id
9
+ field :name
10
+ field :url
11
+
12
+ field :slug
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,16 @@
1
+ module Boxspring
2
+
3
+ class Base < ActiveHash::Base
4
+
5
+ def initialize( attributes = {} )
6
+ attributes.symbolize_keys!
7
+ @attributes = attributes
8
+ attributes.dup.each do | key, value |
9
+ send( "#{key}=", value ) if respond_to?( "#{key}=" )
10
+ end
11
+ yield self if block_given?
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,48 @@
1
+ require 'singleton'
2
+
3
+ module Boxspring
4
+
5
+ def self.configuration( &block )
6
+ Configuration.instance().instance_eval( &block ) unless block.nil?
7
+ Configuration.instance()
8
+ end
9
+
10
+ class Configuration
11
+
12
+ include Singleton
13
+
14
+ def self.reloadable?
15
+ false
16
+ end
17
+
18
+ def self.define_attribute( attribute_name, options = {} )
19
+
20
+ class_eval(
21
+ "def #{attribute_name}( *arguments ); " +
22
+ "@#{attribute_name} = arguments.first unless arguments.empty?; " +
23
+ "@#{attribute_name} || " +
24
+ ( options[ :default ].nil? ?
25
+ "nil" :
26
+ ( options[ :default ].is_a?( String ) ?
27
+ "'#{options[ :default ]}'" :
28
+ "#{options[ :default ]}" ) ) + ";" +
29
+ "end",
30
+ __FILE__,
31
+ __LINE__
32
+ )
33
+ end
34
+
35
+ # the api uri
36
+ define_attribute :api_uri, default: 'http://api.bedrocketplatform.com/'
37
+
38
+ def from_hash( configuration )
39
+
40
+ configuration.each_pair do | name, value |
41
+ self.instance_variable_set( "@#{name}", value )
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,6 @@
1
+ module Boxspring
2
+
3
+ class Error < RuntimeError
4
+ end
5
+
6
+ end
@@ -0,0 +1,128 @@
1
+ module Boxspring
2
+
3
+ class Property < Base
4
+
5
+ def self.find_by( parameters )
6
+
7
+ # filter only acceptable parameters
8
+ parameters = parameters.stringify_keys.slice(
9
+ 'code_name', 'domain_name'
10
+ )
11
+
12
+ # translate attribute names to property identification paramaters
13
+ parameters[ 'property_code' ] = parameters.delete( 'code_name' ) \
14
+ if parameters.include?( 'code_name' )
15
+ parameters[ 'property_domain_name' ] = parameters.delete( 'domain_name' ) \
16
+ if parameters.include?( 'domain_name' )
17
+
18
+ # create and make the request; raise an error if one occurs
19
+ request = Request.new( parameters )
20
+ response = request.get( '/configuration' )
21
+ raise response.error if response.failure?
22
+
23
+ # construct a property; retain the request an apu interface
24
+ Property.new( response.content ).tap do | property |
25
+ property.instance_variable_set( '@api_interface', request )
26
+ end
27
+
28
+ end
29
+
30
+ field :created_at
31
+ field :updated_at
32
+ field :destroyed_at
33
+
34
+ field :name
35
+ field :code_name
36
+ field :domain_name
37
+
38
+ field :meta_description
39
+ field :meta_title
40
+
41
+ def theme
42
+ @_theme ||= begin
43
+ self.attributes.include?( :theme ) ?
44
+ Theme.new( self.attributes[ :theme ] ) :
45
+ nil
46
+ end
47
+ end
48
+
49
+ def tag_collections( reload = false )
50
+ @_tag_collections ||= begin
51
+ self.attributes.include?( :tag_collections ) ?
52
+ self.attributes[ :tag_collections ].map do | tag_collection |
53
+ TagCollection.new( tag_collection )
54
+ end :
55
+ nil
56
+ end
57
+ end
58
+
59
+ def tag_by_id( id )
60
+ response = @api_interface.get( "/tags/#{id}" )
61
+ if ( response.success? )
62
+ Tag.new( response.content )
63
+ elsif ( response.code == '404' )
64
+ nil
65
+ else
66
+ raise response.error
67
+ end
68
+ end
69
+
70
+ def show_by_id( id )
71
+ response = @api_interface.get( "/shows/#{id}" )
72
+ if ( response.success? )
73
+ Show.new( response.content )
74
+ elsif ( response.code == '404' )
75
+ nil
76
+ else
77
+ raise response.error
78
+ end
79
+ end
80
+
81
+ def shows
82
+ @_shows ||= begin
83
+ self.attributes.include?( :shows ) ?
84
+ self.attributes[ :shows ].map do | show |
85
+ Show.new( show )
86
+ end :
87
+ nil
88
+ end
89
+ end
90
+
91
+ def attribution_by_id( id )
92
+ response = @api_interface.get( "/attributions/#{id}" )
93
+ if ( response.success? )
94
+ Attribution.new( response.content )
95
+ elsif ( response.code == '404' )
96
+ nil
97
+ else
98
+ raise response.error
99
+ end
100
+ end
101
+
102
+ def videos( parameters )
103
+ response = @api_interface.get( "/videos", parameters )
104
+ if ( response.success? )
105
+ response.content.map do | video |
106
+ Video.new( video )
107
+ end
108
+ elsif ( response.code == '404' )
109
+ nil
110
+ else
111
+ raise response.error
112
+ end
113
+ end
114
+
115
+ def video_by_id( id )
116
+ response = @api_interface.get( "/videos/#{id}" )
117
+ if ( response.success? )
118
+ Video.new( response.content )
119
+ elsif ( response.code == '404' )
120
+ nil
121
+ else
122
+ raise response.error
123
+ end
124
+ end
125
+
126
+ end
127
+
128
+ end
@@ -0,0 +1,97 @@
1
+ require 'net/https'
2
+
3
+ module Boxspring
4
+
5
+ class Request
6
+
7
+ def initialize( default_parameters = {} )
8
+
9
+ # parse the API uri
10
+ uri = URI.parse( Boxspring.configuration.api_uri )
11
+
12
+ # construct http request
13
+ @http = Net::HTTP.new( uri.host, uri.port )
14
+
15
+ # use ssl when https is the uri scheme
16
+ @http.use_ssl = ( uri.scheme == 'https' )
17
+ @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
18
+
19
+ # retain the default parameters
20
+ @default_parameters = default_parameters.stringify_keys
21
+
22
+ end
23
+
24
+ def get( path, parameters = {} )
25
+
26
+ response = nil
27
+
28
+ begin
29
+
30
+ response =
31
+ Response.new( @http.get( compose_request_path( path, parameters ) ) )
32
+
33
+ rescue Timeout::Error
34
+
35
+ response = nil
36
+
37
+ end
38
+
39
+ response
40
+
41
+ end
42
+
43
+ def post( path, parameters = {} )
44
+
45
+ response = nil
46
+
47
+ begin
48
+
49
+ data = []
50
+
51
+ parameters.each_pair do | key, value |
52
+ data << "#{key.to_s}=#{value.to_s}"
53
+ end
54
+
55
+ response =
56
+ Response.new( @http.post( compose_request_path( path ),
57
+ data.join( '&' ) ) )
58
+
59
+ rescue Timeout::Error
60
+
61
+ response = nil
62
+
63
+ end
64
+
65
+ response
66
+
67
+ end
68
+
69
+ protected; def compose_request_path( path, parameters = {} )
70
+
71
+ # the query
72
+ query = ""
73
+
74
+ # url encode the parameters
75
+ ( @default_parameters.merge( parameters.stringify_keys ) ).each do | key, value |
76
+ query << "#{key}=#{value}&"
77
+ end
78
+
79
+ # chop the trailing '&'
80
+ query.chop!
81
+
82
+ # does path include parameters?
83
+ unless path.include?( '?' )
84
+ # if not, append the query to the url
85
+ path = path + '?' + query
86
+ else
87
+ # if so, append the query to the existing query
88
+ path = path + '&' + query
89
+ end
90
+
91
+ path
92
+
93
+ end
94
+
95
+ end
96
+
97
+ end
@@ -0,0 +1,54 @@
1
+ module Boxspring
2
+
3
+ class Response
4
+
5
+ attr_reader :content
6
+ attr_reader :error
7
+ attr_reader :code
8
+
9
+ def initialize( http_response )
10
+
11
+ @code = http_response.code
12
+ @content = decode_response_body( http_response )
13
+ error = @content.respond_to?( :keys ) ? @content[ 'errors' ] : nil
14
+
15
+ if @content.respond_to?( :include? ) && @content.include?( :errors )
16
+ @error =
17
+ Boxspring::Error.new( @content[ 'errors' ][ 'message' ] )
18
+ end
19
+
20
+ @success =
21
+ http_response.is_a?( Net::HTTPOK ) &&
22
+ @content &&
23
+ @error.nil?
24
+
25
+ @error = Boxspring::Error.new( 'unknown' ) \
26
+ if !@success && @error.nil?
27
+
28
+ end
29
+
30
+ def success?
31
+ @success
32
+ end
33
+
34
+ def failure?
35
+ not @success
36
+ end
37
+
38
+ protected; def decode_response_body( http_response )
39
+
40
+ response = nil
41
+
42
+ body = http_response.body;
43
+ unless body.nil? || body.empty?
44
+ response =
45
+ MultiJson.decode( http_response.body ) rescue nil
46
+ end
47
+
48
+ response
49
+
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,34 @@
1
+ module Boxspring
2
+
3
+ class Show < Base
4
+
5
+ field :created_at
6
+ field :updated_at
7
+ field :published_at
8
+
9
+ field :id
10
+ field :name
11
+ field :short_description
12
+ field :description
13
+ field :schedule
14
+
15
+ field :picture_large_id
16
+ field :picture_medium_id
17
+ field :picture_small_id
18
+
19
+ field :meta_description
20
+ field :meta_title
21
+
22
+ field :slug
23
+
24
+ def private=( _private )
25
+ @_private = ( ( _private == true ) || ( _private =~ /true/i ) ) || false
26
+ end
27
+
28
+ def private
29
+ @_private || false
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,26 @@
1
+ module Boxspring
2
+
3
+ class Tag < Base
4
+
5
+ field :created_at
6
+ field :updated_at
7
+
8
+ field :id
9
+ field :code_name
10
+ field :canonical_name
11
+ field :name
12
+ field :slug
13
+
14
+ field :picture_id
15
+
16
+ def private=( _private )
17
+ @_private = ( ( _private == true ) || ( _private =~ /true/i ) ) || false
18
+ end
19
+
20
+ def private
21
+ @_private || false
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,24 @@
1
+ module Boxspring
2
+
3
+ class TagCollection < Base
4
+
5
+ field :created_at
6
+ field :updated_at
7
+
8
+ field :id
9
+ field :code_name
10
+ field :name
11
+
12
+ def tags
13
+ @_tags ||= begin
14
+ self.attributes.include?( :tags ) ?
15
+ self.attributes[ :tags ].map do | tag |
16
+ Tag.new( tag )
17
+ end :
18
+ nil
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,24 @@
1
+ module Boxspring
2
+
3
+ class Theme < Base
4
+
5
+ field :id
6
+ field :code_name
7
+ field :name
8
+
9
+ field :default_javascript_uri
10
+ field :default_stylesheet_uri
11
+
12
+ def environments( reload = false )
13
+ @_environments ||= begin
14
+ self.attributes.include?( :environments ) ?
15
+ self.attributes[ :environments ].map do | environment |
16
+ ThemeEnvironment.new( environment )
17
+ end :
18
+ nil
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,24 @@
1
+ module Boxspring
2
+
3
+ class ThemeEnvironment < Base
4
+
5
+ field :created_at
6
+ field :updated_at
7
+
8
+ field :code_name
9
+ field :name
10
+ field :description
11
+
12
+ field :uri
13
+
14
+ def user_agent
15
+ @_user_agent ||= begin
16
+ self.attributes.include?( :user_agent ) ?
17
+ UserAgent.new( self.attributes[ :user_agent ] ) :
18
+ nil
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,11 @@
1
+ module Boxspring
2
+
3
+ class UserAgent < Base
4
+
5
+ field :id
6
+ field :name
7
+ field :pattern
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,3 @@
1
+ module Boxspring
2
+ VERSION = '0.0.3'
3
+ end
@@ -0,0 +1,45 @@
1
+ module Boxspring
2
+
3
+ class Video < Base
4
+
5
+ field :created_at
6
+ field :updated_at
7
+ field :uploaded_at
8
+ field :published_at
9
+ field :featured_at
10
+
11
+ field :status
12
+ field :original
13
+ field :publishing_sequence
14
+
15
+ field :type_name
16
+ field :id
17
+ field :name
18
+ field :tagline
19
+ field :short_description
20
+ field :description
21
+
22
+ field :picture_id
23
+
24
+ field :meta_description
25
+ field :meta_title
26
+ field :slug
27
+
28
+ field :show_id
29
+ field :show_episode
30
+ field :show_season
31
+
32
+ field :provider
33
+ field :provider_uid
34
+ field :provider_title
35
+ field :provider_description
36
+ field :provider_url
37
+
38
+ field :duration
39
+ field :action_participations_count
40
+ field :react_actions_counts
41
+ field :views_count
42
+
43
+ end
44
+
45
+ end
data/lib/boxspring.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'multi_json'
2
+ require 'active_hash'
3
+
4
+ require 'boxspring/error'
5
+ require 'boxspring/configuration'
6
+ require 'boxspring/response'
7
+ require 'boxspring/request'
8
+
9
+ require 'boxspring/base'
10
+ require 'boxspring/attribution'
11
+ require 'boxspring/show'
12
+ require 'boxspring/tag'
13
+ require 'boxspring/tag_collection'
14
+ require 'boxspring/user_agent'
15
+ require 'boxspring/theme_environment'
16
+ require 'boxspring/theme'
17
+ require 'boxspring/video'
18
+ require 'boxspring/property'
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boxspring
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Kristoph Cichocki-Romanov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: addressable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: multi_json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: active_hash
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: The boxspring gem is implements a client to the Bedrocket Media Ventrures
70
+ Boxspring property API.
71
+ email: kristoph@bedrocket.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/boxspring.rb
77
+ - lib/boxspring/attribution.rb
78
+ - lib/boxspring/base.rb
79
+ - lib/boxspring/configuration.rb
80
+ - lib/boxspring/error.rb
81
+ - lib/boxspring/property.rb
82
+ - lib/boxspring/request.rb
83
+ - lib/boxspring/response.rb
84
+ - lib/boxspring/show.rb
85
+ - lib/boxspring/tag.rb
86
+ - lib/boxspring/tag_collection.rb
87
+ - lib/boxspring/theme.rb
88
+ - lib/boxspring/theme_environment.rb
89
+ - lib/boxspring/user_agent.rb
90
+ - lib/boxspring/version.rb
91
+ - lib/boxspring/video.rb
92
+ homepage: http://bedrocket.com
93
+ licenses:
94
+ - MS-RL
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.2.2
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Bedrocket Media Ventrures Boxspring property API.
116
+ test_files: []