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 +4 -4
- data/lib/boxxspring/configuration.rb +2 -2
- data/lib/boxxspring/operation.rb +14 -3
- data/lib/boxxspring/parser.rb +23 -2
- data/lib/boxxspring/request.rb +12 -19
- data/lib/boxxspring/resources/artifact.rb +22 -18
- data/lib/boxxspring/resources/attribute_error.rb +7 -0
- data/lib/boxxspring/resources/base.rb +42 -28
- data/lib/boxxspring/resources/card.rb +0 -1
- data/lib/boxxspring/resources/error.rb +2 -1
- data/lib/boxxspring/resources/forbidden_error.rb +6 -0
- data/lib/boxxspring/resources/malformed_parameter_error.rb +6 -0
- data/lib/boxxspring/resources/missing_parameter_error.rb +6 -0
- data/lib/boxxspring/resources/not_found_error.rb +6 -0
- data/lib/boxxspring/resources/property.rb +8 -9
- data/lib/boxxspring/resources/service.rb +0 -1
- data/lib/boxxspring/resources/sponsor.rb +0 -1
- data/lib/boxxspring/resources/task.rb +18 -0
- data/lib/boxxspring/resources/theme.rb +0 -1
- data/lib/boxxspring/resources/theme_environment.rb +0 -1
- data/lib/boxxspring/resources/theme_template.rb +0 -3
- data/lib/boxxspring/resources/user_agent.rb +0 -1
- data/lib/boxxspring/resources/video.rb +1 -1
- data/lib/boxxspring/resources/videos_picture_task.rb +10 -0
- data/lib/boxxspring/response.rb +17 -17
- data/lib/boxxspring/serializer.rb +31 -0
- data/lib/boxxspring/version.rb +1 -1
- data/lib/boxxspring.rb +12 -1
- metadata +10 -3
- data/lib/boxxspring/error.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0be8421b40d41130cfeda34c01efff834418a751
|
4
|
+
data.tar.gz: b148bf88e23a44832b3c2b36200ebd068c448ff4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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: '
|
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
|
|
data/lib/boxxspring/operation.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
66
|
+
protected; def normalize_include( *arguments )
|
56
67
|
|
57
68
|
includes = {};
|
58
69
|
arguments.each do | argument |
|
data/lib/boxxspring/parser.rb
CHANGED
@@ -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' ][ '
|
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
|
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 )
|
data/lib/boxxspring/request.rb
CHANGED
@@ -27,10 +27,9 @@ module Boxxspring
|
|
27
27
|
response = nil
|
28
28
|
|
29
29
|
begin
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
6
|
-
field :id
|
5
|
+
field :id
|
7
6
|
|
8
|
-
field
|
9
|
-
field
|
10
|
-
field
|
11
|
-
field
|
7
|
+
field :created_at
|
8
|
+
field :updated_at
|
9
|
+
field :edited_at
|
10
|
+
field :published_at
|
12
11
|
|
13
|
-
field
|
14
|
-
field
|
12
|
+
field :state
|
13
|
+
field :original
|
15
14
|
|
16
|
-
field
|
17
|
-
field
|
18
|
-
field
|
19
|
-
field
|
15
|
+
field :name
|
16
|
+
field :short_description
|
17
|
+
field :description
|
18
|
+
field :note
|
20
19
|
|
21
|
-
field
|
20
|
+
field :artifact_ids
|
21
|
+
field :card_ids
|
22
22
|
|
23
|
-
field
|
24
|
-
|
25
|
-
field
|
23
|
+
field :picture_id
|
24
|
+
|
25
|
+
field :meta_description
|
26
|
+
field :meta_title
|
27
|
+
field :slug
|
26
28
|
|
27
|
-
field
|
28
|
-
field
|
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
|
@@ -2,42 +2,56 @@ module Boxxspring
|
|
2
2
|
|
3
3
|
class Base
|
4
4
|
|
5
|
-
|
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
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
39
|
-
|
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 |
|
@@ -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
|
-
|
9
|
-
|
10
|
-
|
7
|
+
field :created_at
|
8
|
+
field :updated_at
|
9
|
+
field :destroyed_at
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
field :name
|
12
|
+
field :code_name
|
13
|
+
field :domain_name
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
field :meta_description
|
16
|
+
field :meta_title
|
18
17
|
|
19
18
|
field :authentication_enabled, default: false
|
20
19
|
field :authentication_username
|
data/lib/boxxspring/response.rb
CHANGED
@@ -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
|
-
@
|
13
|
-
error = @content.respond_to?( :keys ) ? @content[ 'errors' ] : nil
|
13
|
+
@resources = []
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
data/lib/boxxspring/version.rb
CHANGED
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.
|
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
|
+
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:
|