boxxspring 2.0.16 → 2.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3dfdb7b50d621bdf111ee92ab7724bb5d2ab4cb
4
- data.tar.gz: cd5084cb457165b2041bcb96b04c2764c3550c17
3
+ metadata.gz: 0be8421b40d41130cfeda34c01efff834418a751
4
+ data.tar.gz: b148bf88e23a44832b3c2b36200ebd068c448ff4
5
5
  SHA512:
6
- metadata.gz: 6b61cba0d1e031159b0b80e5fbbddbf7417fb11e6bad14c1ff742b7a708c050dbdbcd277e2ca849633f243b95d77f1b34d734a9ff4b48f7c6a3ef12a82bb3d81
7
- data.tar.gz: 9e4fe19be37a24b5c2333314b86b1892d4672e0fc98a92059625ae33f628ed6d97f128d697bcd45e20f15301f57d92fbe4c5f3ec525cb4312c74f74f8f796c60
6
+ metadata.gz: 6358f4752f69b684fac237514a8f9a3b7d5723800c70f14afa880d511b551598ab1c122771b89faa9ecc59d376795ba4cce99c9a6e8a5248d70dcd5479d03185
7
+ data.tar.gz: 9517160038a589139d486f1c4159df02b817bc623c06dd586d83e09115b384980519673cc9d8f9a880a4d023f563e6c8d8d9ad78016ba458db6b623d8d1c22a4
@@ -32,8 +32,8 @@ module Boxxspring
32
32
  )
33
33
  end
34
34
 
35
- # the api uri
36
- define_attribute :api_uri, default: 'http://api-staging.bedrocketplatform.com/'
35
+ # the api uri; DO NOT COMMIT A MODIFIED DEFAULT
36
+ define_attribute :api_uri, default: 'https://api.boxxspring.com'
37
37
 
38
38
  def from_hash( configuration )
39
39
 
@@ -31,8 +31,7 @@ module Boxxspring
31
31
  result = nil
32
32
  Boxxspring::Request.new.tap do | request |
33
33
  request.get( @path, @parameters ).tap do | response |
34
- parser = Boxxspring::Parser.new( response.content )
35
- result = parser.resources
34
+ result = response.resources
36
35
  result = result.first if result.length > 0 && @result == Object
37
36
  end
38
37
  end
@@ -45,6 +44,18 @@ module Boxxspring
45
44
  result
46
45
  end
47
46
 
47
+ def write( node, objects )
48
+ result = nil
49
+ Boxxspring::Request.new.tap do | request |
50
+ serializer = Boxxspring::Serializer.new( objects )
51
+ response = request.post( @path, @parameters, serializer.serialize( node ) )
52
+ if response.present?
53
+ result = response.resources
54
+ end
55
+ end
56
+ result
57
+ end
58
+
48
59
  protected; def spawn( parameters )
49
60
  Boxxspring::Operation.new(
50
61
  @path,
@@ -52,7 +63,7 @@ module Boxxspring
52
63
  )
53
64
  end
54
65
 
55
- public; def normalize_include( *arguments )
66
+ protected; def normalize_include( *arguments )
56
67
 
57
68
  includes = {};
58
69
  arguments.each do | argument |
@@ -4,6 +4,7 @@ module Boxxspring
4
4
 
5
5
  def initialize( content = {} )
6
6
  @content = content
7
+ yield self if block_given?
7
8
  end
8
9
 
9
10
  def name
@@ -14,10 +15,14 @@ module Boxxspring
14
15
 
15
16
  def type_name
16
17
  @content.include?( '$this' ) ?
17
- @content[ '$this' ][ 'name' ] :
18
+ @content[ '$this' ][ 'type_name' ] :
18
19
  nil
19
20
  end
20
21
 
22
+ def type_name?( name )
23
+ self.type_name == name.to_s
24
+ end
25
+
21
26
  def key
22
27
  'id'
23
28
  end
@@ -43,12 +48,22 @@ module Boxxspring
43
48
  end
44
49
 
45
50
  def resource_by( name, key )
51
+
46
52
  @resources_index ||= Hash.new { | hash, key | hash[ key ] = {} }
53
+ @resource_index_mutex ||= Hash.new { | hash, key | hash[ key ] = [] }
54
+
47
55
  @resources_index[ name ][ key ] ||= begin
56
+
57
+ # lock the resource index for this name/key combination
58
+ # note: this prevents boxxspring objects that are associated with
59
+ # themselves from causing a stack overflow
60
+ return nil if @resource_index_mutex[ name ].include?( key )
61
+ @resource_index_mutex[ name ].push( key )
62
+
48
63
  result = nil
49
64
  resource_attributes = resource_attribute_index[ name ][ key ]
50
65
  if resource_attributes.present?
51
- type_name = resource_attributes.delete( 'type_name' ) || self.type_name
66
+ type_name = resource_attributes[ 'type_name' ] || self.type_name
52
67
  klass = Boxxspring.const_get( type_name.classify ) rescue nil
53
68
  if klass.present?
54
69
  result = klass.new(
@@ -57,8 +72,14 @@ module Boxxspring
57
72
  )
58
73
  end
59
74
  end
75
+
76
+ # unlock the resource index for this name/key combination
77
+ @resource_index_mutex[ name ].delete( key )
78
+
60
79
  result
80
+
61
81
  end
82
+
62
83
  end
63
84
 
64
85
  def resource_associations_by( name, key )
@@ -27,10 +27,9 @@ module Boxxspring
27
27
  response = nil
28
28
 
29
29
  begin
30
-
31
- response =
32
- Response.new( @http.get( compose_request_path( path, parameters ) ) )
33
-
30
+ response = Response.new(
31
+ @http.get( compose_request_path( path, parameters ) )
32
+ )
34
33
  rescue Timeout::Error
35
34
  response = nil
36
35
  end
@@ -39,25 +38,19 @@ module Boxxspring
39
38
 
40
39
  end
41
40
 
42
- def post( path, parameters = {} )
41
+ def post( path, parameters = {}, body = {} )
43
42
 
44
43
  response = nil
45
44
 
46
45
  begin
47
-
48
- data = []
49
-
50
- parameters.each_pair do | key, value |
51
- data << "#{key.to_s}=#{value.to_s}"
52
- end
53
-
54
- response =
55
- Response.new(
56
- @http.post(
57
- compose_request_path( path ),
58
- data.join( '&' )
59
- )
60
- )
46
+
47
+ request = Net::HTTP::Post.new(
48
+ compose_request_path( path, parameters ),
49
+ { 'Content-Type' =>'application/json' }
50
+ )
51
+ request.body = body.to_json
52
+
53
+ response = Response.new( @http.request( request ) )
61
54
 
62
55
  rescue Timeout::Error
63
56
  response = nil
@@ -2,30 +2,32 @@ module Boxxspring
2
2
 
3
3
  class Artifact < Base
4
4
 
5
- field :type_name
6
- field :id
5
+ field :id
7
6
 
8
- field :created_at
9
- field :updated_at
10
- field :edited_at
11
- field :published_at
7
+ field :created_at
8
+ field :updated_at
9
+ field :edited_at
10
+ field :published_at
12
11
 
13
- field :state
14
- field :original
12
+ field :state
13
+ field :original
15
14
 
16
- field :name
17
- field :short_description
18
- field :description
19
- field :note
15
+ field :name
16
+ field :short_description
17
+ field :description
18
+ field :note
20
19
 
21
- field :picture_id
20
+ field :artifact_ids
21
+ field :card_ids
22
22
 
23
- field :meta_description
24
- field :meta_title
25
- field :slug
23
+ field :picture_id
24
+
25
+ field :meta_description
26
+ field :meta_title
27
+ field :slug
26
28
 
27
- field :sponsor_id
28
- field :template_id
29
+ field :sponsor_id
30
+ field :template_id
29
31
 
30
32
  has_one :attribution
31
33
 
@@ -34,6 +36,8 @@ module Boxxspring
34
36
  has_many :cards
35
37
  has_many :sponsors
36
38
 
39
+ has_many :errors
40
+
37
41
  end
38
42
 
39
43
  end
@@ -0,0 +1,7 @@
1
+ module Boxxspring
2
+
3
+ class AttributeError < Error
4
+ field :attribute
5
+ end
6
+
7
+ end
@@ -2,42 +2,56 @@ module Boxxspring
2
2
 
3
3
  class Base
4
4
 
5
- def self.field( name, options = {} )
6
-
7
- class_eval(
8
- "def #{name}(); " +
9
- "@#{name} || " +
10
- ( options[ :default ].nil? ?
11
- "nil" :
12
- ( options[ :default ].is_a?( String ) ?
13
- "'#{options[ :default ]}'" :
14
- "#{options[ :default ]}" ) ) + ";" +
15
- "end;" +
16
- " " +
17
- "attr_writer :#{name};",
18
- __FILE__,
19
- __LINE__
20
- )
5
+ class << self
21
6
 
22
- end
7
+ def inherited( subclass )
8
+ subclass.fields = {}.merge( self.fields )
9
+ end
10
+
11
+ def field( name, options = {} )
12
+
13
+ self.fields[ name.to_sym ] = options.merge( name: name )
14
+
15
+ class_eval(
16
+ "def #{name}(); " +
17
+ "@#{name} || " +
18
+ ( options[ :default ].nil? ?
19
+ "nil" :
20
+ ( options[ :default ].is_a?( String ) ?
21
+ "'#{options[ :default ]}'" :
22
+ "#{options[ :default ]}" ) ) + ";" +
23
+ "end;" +
24
+ " " +
25
+ "attr_writer :#{name};",
26
+ __FILE__,
27
+ __LINE__
28
+ )
23
29
 
24
- def self.has_one( name, options = {} )
25
- define_method name do
26
- associations = self.instance_variable_get( "@_#{name.to_s.pluralize}" )
27
- associations.present? ? associations.first : options[ :default ]
28
30
  end
29
- end
30
31
 
31
- def self.has_many( name, options = {} )
32
- define_method name do
33
- self.instance_variable_get( "@_#{name}" ) || options[ :default ] || []
32
+ def has_one( name, options = {} )
33
+ define_method name do
34
+ associations = self.instance_variable_get( "@_#{name.to_s.pluralize}" )
35
+ associations.present? ? associations.first : options[ :default ]
36
+ end
34
37
  end
38
+
39
+ def has_many( name, options = {} )
40
+ define_method name do
41
+ self.instance_variable_get( "@_#{name}" ) || options[ :default ] || []
42
+ end
43
+ end
44
+
35
45
  end
36
46
 
47
+ class_attribute :fields, instance_writer: false
48
+ self.fields = {}
49
+
50
+ field :type_name
51
+
37
52
  def initialize( attributes = {}, associations = {} )
38
- attributes.symbolize_keys!
39
- @attributes = attributes
40
- attributes.dup.each do | key, value |
53
+ self.type_name = self.class.name.gsub( /Boxxspring::/, '' ).underscore
54
+ attributes.each do | key, value |
41
55
  send( "#{key}=", value ) if respond_to?( "#{key}=" )
42
56
  end
43
57
  associations.each do | key, value |
@@ -5,7 +5,6 @@ module Boxxspring
5
5
  field :created_at
6
6
  field :updated_at
7
7
 
8
- field :type_name
9
8
  field :id
10
9
  field :name
11
10
  field :body
@@ -1,6 +1,7 @@
1
1
  module Boxxspring
2
2
 
3
- class Error < RuntimeError
3
+ class Error < Base
4
+ field :message
4
5
  end
5
6
 
6
7
  end
@@ -0,0 +1,6 @@
1
+ module Boxxspring
2
+
3
+ class ForbiddenError < Error
4
+ end
5
+
6
+ end
@@ -0,0 +1,6 @@
1
+ module Boxxspring
2
+
3
+ class MalformedParameterError < Error
4
+ end
5
+
6
+ end
@@ -0,0 +1,6 @@
1
+ module Boxxspring
2
+
3
+ class MissingParameterError < Error
4
+ end
5
+
6
+ end
@@ -0,0 +1,6 @@
1
+ module Boxxspring
2
+
3
+ class NotFoundError < Error
4
+ end
5
+
6
+ end
@@ -2,19 +2,18 @@ module Boxxspring
2
2
 
3
3
  class Property < Base
4
4
 
5
- field :type_name
6
5
  field :id
7
6
 
8
- field :created_at
9
- field :updated_at
10
- field :destroyed_at
7
+ field :created_at
8
+ field :updated_at
9
+ field :destroyed_at
11
10
 
12
- field :name
13
- field :code_name
14
- field :domain_name
11
+ field :name
12
+ field :code_name
13
+ field :domain_name
15
14
 
16
- field :meta_description
17
- field :meta_title
15
+ field :meta_description
16
+ field :meta_title
18
17
 
19
18
  field :authentication_enabled, default: false
20
19
  field :authentication_username
@@ -5,7 +5,6 @@ module Boxxspring
5
5
  field :created_at
6
6
  field :updated_at
7
7
 
8
- field :type_name
9
8
  field :id
10
9
  field :provider
11
10
  field :public_settings
@@ -5,7 +5,6 @@ module Boxxspring
5
5
  field :created_at
6
6
  field :updated_at
7
7
 
8
- field :type_name
9
8
  field :id
10
9
  field :name
11
10
  field :picture_id
@@ -0,0 +1,18 @@
1
+ module Boxxspring
2
+
3
+ class Task < Base
4
+
5
+ field :created_at
6
+ field :updated_at
7
+
8
+ field :id
9
+
10
+ field :state
11
+ field :started_at
12
+ field :ended_at
13
+
14
+ has_one :property
15
+
16
+ end
17
+
18
+ end
@@ -2,7 +2,6 @@ module Boxxspring
2
2
 
3
3
  class Theme < Base
4
4
 
5
- field :type_name
6
5
  field :id
7
6
  field :code_name
8
7
  field :name
@@ -2,7 +2,6 @@ module Boxxspring
2
2
 
3
3
  class ThemeEnvironment < Base
4
4
 
5
- field :type_name
6
5
  field :id
7
6
 
8
7
  field :created_at
@@ -1,10 +1,7 @@
1
1
  module Boxxspring
2
2
 
3
3
  class ThemeTemplate < Base
4
-
5
- field :type_name
6
4
  field :code_name
7
-
8
5
  end
9
6
 
10
7
  end
@@ -2,7 +2,6 @@ module Boxxspring
2
2
 
3
3
  class UserAgent < Base
4
4
 
5
- field :type_name
6
5
  field :id
7
6
 
8
7
  field :name
@@ -15,4 +15,4 @@ module Boxxspring
15
15
 
16
16
  end
17
17
 
18
- end
18
+ end
@@ -0,0 +1,10 @@
1
+ module Boxxspring
2
+
3
+ class VideosPictureTask < Task
4
+
5
+ field :timecode
6
+ field :picture_id
7
+
8
+ end
9
+
10
+ end
@@ -2,29 +2,29 @@ module Boxxspring
2
2
 
3
3
  class Response
4
4
 
5
- attr_reader :content
6
- attr_reader :error
7
5
  attr_reader :code
6
+ attr_reader :resources
8
7
 
9
8
  def initialize( http_response )
10
9
 
10
+ @success = http_response.is_a?( Net::HTTPOK )
11
+
11
12
  @code = http_response.code
12
- @content = decode_response_body( http_response )
13
- error = @content.respond_to?( :keys ) ? @content[ 'errors' ] : nil
13
+ @resources = []
14
14
 
15
- if @content.respond_to?( :include? ) && @content.include?( 'errors' )
16
- @error =
17
- Boxxspring::Error.new( @content[ 'errors' ][ 'message' ] )
15
+ content = decode_response_body( http_response )
16
+ if ( content && content.respond_to?( :keys ) )
17
+ Boxxspring::Parser.new( content ) do | parser |
18
+ @resources = parser.resources
19
+ @success = !parser.type_name?( :error )
20
+ end
21
+ else
22
+ @success = false
23
+ @resources << Boxxspring::Error.new(
24
+ message: "An unknown error occured (#{@code})."
25
+ )
18
26
  end
19
-
20
- @success =
21
- http_response.is_a?( Net::HTTPOK ) &&
22
- @content.present? &&
23
- @error.nil?
24
-
25
- @error = Boxxspring::Error.new( 'unknown' ) \
26
- if !@success && @error.nil?
27
-
27
+
28
28
  end
29
29
 
30
30
  def success?
@@ -39,7 +39,7 @@ module Boxxspring
39
39
 
40
40
  response = nil
41
41
 
42
- body = http_response.body;
42
+ body = http_response.body;
43
43
  unless body.nil? || body.empty?
44
44
  response =
45
45
  MultiJson.decode( http_response.body ) rescue nil
@@ -0,0 +1,31 @@
1
+ module Boxxspring
2
+
3
+ class Serializer
4
+
5
+ def initialize( payload = [], options = {} )
6
+ @payload = [ payload ].flatten
7
+ @options = options
8
+ end
9
+
10
+ def serialize( node, options = {} )
11
+ result = {}
12
+ result[ node ] = @payload.map do | object |
13
+ node_object = {}
14
+ node_object[ :type_name ] = (
15
+ object.respond_to?( :type_name ) ?
16
+ object.type_name :
17
+ object.class.name.gsub( /Boxxspring::/, '' ).underscore
18
+ )
19
+ if object.respond_to?( :fields )
20
+ object.fields.each do | name, options |
21
+ node_object[ name.to_sym ] = object.send( name )
22
+ end
23
+ end
24
+ node_object
25
+ end
26
+ result
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Boxxspring
2
- VERSION = '2.0.16'
2
+ VERSION = '2.1.1'
3
3
  end
data/lib/boxxspring.rb CHANGED
@@ -2,14 +2,23 @@ require 'active_support'
2
2
  require 'active_support/all'
3
3
  require 'multi_json'
4
4
 
5
- require 'boxxspring/error'
6
5
  require 'boxxspring/configuration'
7
6
  require 'boxxspring/response'
8
7
  require 'boxxspring/request'
9
8
  require 'boxxspring/parser'
9
+ require 'boxxspring/serializer'
10
10
  require 'boxxspring/operation'
11
11
 
12
12
  require 'boxxspring/resources/base'
13
+
14
+ require 'boxxspring/resources/error'
15
+ require 'boxxspring/resources/forbidden_error'
16
+ require 'boxxspring/resources/attribute_error'
17
+ require 'boxxspring/resources/missing_parameter_error'
18
+ require 'boxxspring/resources/attribute_error'
19
+ require 'boxxspring/resources/malformed_parameter_error'
20
+ require 'boxxspring/resources/not_found_error'
21
+
13
22
  require 'boxxspring/resources/picture'
14
23
  require 'boxxspring/resources/user_agent'
15
24
  require 'boxxspring/resources/theme_environment'
@@ -37,3 +46,5 @@ require 'boxxspring/resources/playlist'
37
46
  require 'boxxspring/resources/group'
38
47
  require 'boxxspring/resources/property'
39
48
  require 'boxxspring/resources/service'
49
+ require 'boxxspring/resources/task'
50
+ require 'boxxspring/resources/videos_picture_task'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxxspring
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.16
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristoph Cichocki-Romanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-25 00:00:00.000000000 Z
11
+ date: 2014-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -75,18 +75,22 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - lib/boxxspring.rb
77
77
  - lib/boxxspring/configuration.rb
78
- - lib/boxxspring/error.rb
79
78
  - lib/boxxspring/operation.rb
80
79
  - lib/boxxspring/parser.rb
81
80
  - lib/boxxspring/request.rb
82
81
  - lib/boxxspring/resources/artifact.rb
83
82
  - lib/boxxspring/resources/atomic_video_card.rb
83
+ - lib/boxxspring/resources/attribute_error.rb
84
84
  - lib/boxxspring/resources/attribution.rb
85
85
  - lib/boxxspring/resources/author.rb
86
86
  - lib/boxxspring/resources/base.rb
87
87
  - lib/boxxspring/resources/card.rb
88
88
  - lib/boxxspring/resources/error.rb
89
+ - lib/boxxspring/resources/forbidden_error.rb
89
90
  - lib/boxxspring/resources/group.rb
91
+ - lib/boxxspring/resources/malformed_parameter_error.rb
92
+ - lib/boxxspring/resources/missing_parameter_error.rb
93
+ - lib/boxxspring/resources/not_found_error.rb
90
94
  - lib/boxxspring/resources/organization.rb
91
95
  - lib/boxxspring/resources/page.rb
92
96
  - lib/boxxspring/resources/picture.rb
@@ -100,6 +104,7 @@ files:
100
104
  - lib/boxxspring/resources/sponsor.rb
101
105
  - lib/boxxspring/resources/story.rb
102
106
  - lib/boxxspring/resources/tag.rb
107
+ - lib/boxxspring/resources/task.rb
103
108
  - lib/boxxspring/resources/team.rb
104
109
  - lib/boxxspring/resources/text_card.rb
105
110
  - lib/boxxspring/resources/theme.rb
@@ -109,7 +114,9 @@ files:
109
114
  - lib/boxxspring/resources/video.rb
110
115
  - lib/boxxspring/resources/video_card.rb
111
116
  - lib/boxxspring/resources/video_source.rb
117
+ - lib/boxxspring/resources/videos_picture_task.rb
112
118
  - lib/boxxspring/response.rb
119
+ - lib/boxxspring/serializer.rb
113
120
  - lib/boxxspring/version.rb
114
121
  homepage: http://bedrocket.com
115
122
  licenses:
@@ -1,6 +0,0 @@
1
- module Boxxspring
2
-
3
- class Error < RuntimeError
4
- end
5
-
6
- end