arbor 0.0.2 → 0.0.3
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/README.md +1 -1
- data/lib/arbor/api.rb +12 -8
- data/lib/arbor/errors.rb +2 -1
- data/lib/arbor/model/abstract.rb +9 -1
- data/lib/arbor/query.rb +1 -5
- data/lib/arbor/utils.rb +7 -6
- data/lib/arbor/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b4a455a9b06989723d91f8d5419b8e4d1eaa731
|
4
|
+
data.tar.gz: 9058985b086831ec3c748bf57f876318607aa216
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f6971c9eb5ad2bb2812c33092c97122af8cdfa377e6fb732948843ef580c39c9b5385d109c2d39d416c5417485de9f8983ab6b7200a54bb0da196b0dd8a9ee3
|
7
|
+
data.tar.gz: 1e811aeb1400e1a056d180668e4929ad37d46421b09c9bac38aff600e8ad195122d23b603f8b4f906c4599b3d899eb39b1c6a3b1fa0c338032a60a23973e078e
|
data/README.md
CHANGED
data/lib/arbor/api.rb
CHANGED
@@ -3,30 +3,30 @@ require 'arbor/model/serialiser'
|
|
3
3
|
module Arbor
|
4
4
|
module API
|
5
5
|
def retrieve(type, id)
|
6
|
-
resource =
|
7
|
-
data = get("/rest-v2/#{resource}/#{id}")
|
6
|
+
resource = parse_resource_name(type)
|
7
|
+
data = get("/rest-v2/#{resource.dasherize}/#{id}")
|
8
8
|
|
9
9
|
unmarshall_data(data, resource)
|
10
10
|
end
|
11
11
|
|
12
12
|
def query(type, query = nil)
|
13
|
-
resource =
|
13
|
+
resource = parse_resource_name(type)
|
14
14
|
query_string = query.build_query_string if query
|
15
15
|
|
16
|
-
data = get("/rest-v2/#{resource}?#{query_string}")
|
16
|
+
data = get("/rest-v2/#{resource.dasherize}?#{query_string}")
|
17
17
|
|
18
18
|
unmarshall_data(data, resource)
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
22
22
|
def unmarshall_data(data, resource)
|
23
|
-
singular_resource = resource.
|
24
|
-
plural_resource = resource.
|
23
|
+
singular_resource = resource.singularize.camelize(:lower)
|
24
|
+
plural_resource = resource.camelize(:lower)
|
25
25
|
|
26
26
|
if (res = data[singular_resource])
|
27
27
|
Model::Serialiser.parse_resource(res).tap { |obj|
|
28
28
|
obj.attach_client(self) if obj.respond_to?(:attach_client)
|
29
|
-
obj.lock_attributes = true
|
29
|
+
obj.lock_attributes = true if obj.respond_to?(:lock_attributes)
|
30
30
|
}
|
31
31
|
elsif data[plural_resource]
|
32
32
|
data[plural_resource].map do |res|
|
@@ -34,8 +34,12 @@ module Arbor
|
|
34
34
|
obj.attach_client(self) if obj.respond_to?(:attach_client)
|
35
35
|
}
|
36
36
|
end
|
37
|
+
elsif data.empty?
|
38
|
+
[]
|
39
|
+
elsif data["errors"]
|
40
|
+
raise Errors::APIError, "#{data["status"]["code"]} #{data["status"]["reason"]}: #{data["status"]["errors"].join(", ")}"
|
37
41
|
else
|
38
|
-
raise Errors::SerialisationError, "Unexpected root key in API data."
|
42
|
+
raise Errors::SerialisationError, "Unexpected root key in API data. Expected: #{plural_resource} or #{singular_resource}. Actual: #{data.keys}"
|
39
43
|
end
|
40
44
|
end
|
41
45
|
end
|
data/lib/arbor/errors.rb
CHANGED
data/lib/arbor/model/abstract.rb
CHANGED
@@ -24,7 +24,7 @@ module Arbor
|
|
24
24
|
|
25
25
|
data = api_client.get(href)
|
26
26
|
|
27
|
-
parsed_attributes = Serialiser.parse_attributes(data[entity_type.
|
27
|
+
parsed_attributes = Serialiser.parse_attributes(data[entity_type.camelize(:lower)])
|
28
28
|
load_attributes(parsed_attributes)
|
29
29
|
attach_client(self.api_client)
|
30
30
|
|
@@ -64,6 +64,14 @@ module Arbor
|
|
64
64
|
def unlock_attributes
|
65
65
|
@attribute_lock = false
|
66
66
|
end
|
67
|
+
|
68
|
+
def attributes
|
69
|
+
Hash[attribute_names.map { |a| [a, send(a)] }]
|
70
|
+
end
|
71
|
+
|
72
|
+
def inspect
|
73
|
+
"#<#{self.class.name} #{attribute_names.map { |a| "#{a}: #{send(a).inspect}" }.join(', ')}>"
|
74
|
+
end
|
67
75
|
end
|
68
76
|
end
|
69
77
|
end
|
data/lib/arbor/query.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
require 'uri'
|
2
|
-
require 'arbor/utils'
|
3
2
|
require 'arbor/filter'
|
4
3
|
|
5
4
|
module Arbor
|
6
5
|
class Query
|
7
|
-
include Arbor::Utils
|
8
|
-
|
9
6
|
attr_accessor :filters, :resource
|
10
7
|
|
11
|
-
def initialize(
|
12
|
-
@resource = parse_resource(type)
|
8
|
+
def initialize(filters = [])
|
13
9
|
@filters = filters
|
14
10
|
end
|
15
11
|
|
data/lib/arbor/utils.rb
CHANGED
@@ -2,21 +2,22 @@ require 'active_support/core_ext/string'
|
|
2
2
|
|
3
3
|
module Arbor
|
4
4
|
module Utils
|
5
|
-
def
|
6
|
-
validate(
|
5
|
+
def parse_resource_name(type)
|
6
|
+
validate(get_resource_name(type), Arbor::RESOURCES)
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def get_resource_name(type)
|
10
10
|
case type
|
11
11
|
when Class
|
12
|
-
|
12
|
+
# do reverse serialiser lookup instead
|
13
|
+
type.name.pluralize.underscore
|
13
14
|
else
|
14
|
-
type.to_s.pluralize
|
15
|
+
type.to_s.pluralize
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
19
|
def validate(choice, options)
|
19
|
-
unless options.include?(choice)
|
20
|
+
unless options.include?(choice.to_sym)
|
20
21
|
raise ArgumentError, "#{choice} is not a valid option: #{options}"
|
21
22
|
end
|
22
23
|
choice
|
data/lib/arbor/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arbor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Campbell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|