infobase 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/infobase/base.rb +46 -2
- data/lib/infobase/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: 14bcf51e33c14d629c7de37d387b63d20eb47b9f
|
4
|
+
data.tar.gz: e2b5143f86d69be05beebf49733581d8fafc7097
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9db033f9c755ce429bc40a0670f16808c79b14b3beb54da86a8bffbcee63b301f7e5e64b97926b96f2e9f78502f594dd50930d37b002708683579f4d8bd4d755
|
7
|
+
data.tar.gz: c309bacf3b9a54c0ebcd3b262445f163a9d42c8eec67f40a89ffd3f51c9d97946cf89519c27568b3fe2c34b05a030bc0b364f1cf6791805a2abfd9b764c33d1d
|
data/lib/infobase/base.rb
CHANGED
@@ -5,10 +5,46 @@ require 'retryable'
|
|
5
5
|
module Infobase
|
6
6
|
class Base
|
7
7
|
|
8
|
+
def initialize(hash)
|
9
|
+
@item = hash
|
10
|
+
end
|
11
|
+
|
12
|
+
def [](key)
|
13
|
+
@item[key.to_s]
|
14
|
+
end
|
15
|
+
|
16
|
+
def keys
|
17
|
+
@item.keys
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
@item['to_s'] || super
|
22
|
+
end
|
23
|
+
|
24
|
+
def method_missing(symbol, &block)
|
25
|
+
key = symbol.to_s
|
26
|
+
|
27
|
+
return @item[key] if @item.keys.include?(key)
|
28
|
+
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
def respond_to?(symbol, include_private = false)
|
33
|
+
@item.keys.include?(symbol.to_s) || super
|
34
|
+
end
|
35
|
+
|
8
36
|
def self.find(id, params = {})
|
9
37
|
request(:get, params, path_with_id(id))
|
10
38
|
end
|
11
39
|
|
40
|
+
def self.singular_name
|
41
|
+
to_s.split('::').last.underscore
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.plural_name
|
45
|
+
singular_name.pluralize
|
46
|
+
end
|
47
|
+
|
12
48
|
def self.get(params = {})
|
13
49
|
request(:get, params)
|
14
50
|
end
|
@@ -25,6 +61,9 @@ module Infobase
|
|
25
61
|
request(:delete, {}, path_with_id(id))
|
26
62
|
end
|
27
63
|
|
64
|
+
def self.search(params = {})
|
65
|
+
request(:post, params, "#{default_path}/search")
|
66
|
+
end
|
28
67
|
|
29
68
|
def self.request(method, params, path = nil)
|
30
69
|
raise 'You need to configure Infobase with your access_token.' unless Infobase.access_token
|
@@ -53,7 +92,12 @@ module Infobase
|
|
53
92
|
def self.handle_response(response, request, result)
|
54
93
|
case response.code
|
55
94
|
when 200..299
|
56
|
-
Oj.load(response)
|
95
|
+
json = Oj.load(response)
|
96
|
+
if json[singular_name]
|
97
|
+
new(json[singular_name])
|
98
|
+
else
|
99
|
+
json[plural_name].collect { |hash| new(hash) }
|
100
|
+
end
|
57
101
|
when 400
|
58
102
|
raise RestClient::BadRequest, response
|
59
103
|
when 500
|
@@ -66,7 +110,7 @@ module Infobase
|
|
66
110
|
end
|
67
111
|
|
68
112
|
def self.default_path
|
69
|
-
|
113
|
+
plural_name
|
70
114
|
end
|
71
115
|
|
72
116
|
def self.path_with_id(id)
|
data/lib/infobase/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infobase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Starcher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|