sifiapi 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +2 -2
- data/lib/sifi_api/resource.rb +4 -1
- data/lib/sifi_api/resource_collection.rb +73 -0
- data/lib/sifi_api/segment_tag.rb +2 -0
- data/lib/sifi_api/version.rb +1 -1
- data/lib/sifi_api.rb +2 -0
- data/spec/sifi_api/segment_tag_spec.rb +7 -0
- metadata +14 -16
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2012
|
1
|
+
Copyright (c) 2012 Simpli.fi
|
2
2
|
|
3
3
|
MIT License
|
4
4
|
|
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/sifi_api/resource.rb
CHANGED
@@ -8,6 +8,7 @@ class SifiApi::Resource
|
|
8
8
|
@connection = connection
|
9
9
|
@user_key = user_key
|
10
10
|
@cache = {}
|
11
|
+
@paging = false
|
11
12
|
end
|
12
13
|
|
13
14
|
def raw_json
|
@@ -31,6 +32,7 @@ class SifiApi::Resource
|
|
31
32
|
resource_name = resource.to_s.pluralize
|
32
33
|
response = @connection.post(@user_key, self.resource + "/#{resource_name}", params)
|
33
34
|
if response && response.body
|
35
|
+
handle_response
|
34
36
|
record = response.body[resource_name].first
|
35
37
|
SifiApi.const_get(resource.to_s.classify).new(record, @connection, @user_key)
|
36
38
|
end
|
@@ -71,7 +73,7 @@ class SifiApi::Resource
|
|
71
73
|
a << resource
|
72
74
|
end
|
73
75
|
end
|
74
|
-
a
|
76
|
+
SifiApi::ResourceCollection.new(resource_name, a, response.body["paging"], connection, user_key)
|
75
77
|
end
|
76
78
|
|
77
79
|
def method_missing(sym, *args, &block)
|
@@ -133,6 +135,7 @@ class SifiApi::Resource
|
|
133
135
|
@json[name].each do |record|
|
134
136
|
records << SifiApi.const_get(name.classify).new(record, @connection, @user_key)
|
135
137
|
end
|
138
|
+
records = SifiApi::ResourceCollection.new(name, records, nil, @connection, @user_key)
|
136
139
|
else
|
137
140
|
records = SifiApi.const_get(name.classify).get_via_uri(@connection, @user_key, uri, params)
|
138
141
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
class SifiApi::ResourceCollection
|
2
|
+
|
3
|
+
def initialize(resource_name, resources, paging, connection, user_key)
|
4
|
+
@resource_name = resource_name
|
5
|
+
@resources = resources
|
6
|
+
@paging = paging || {}
|
7
|
+
@connection = connection
|
8
|
+
@user_key = user_key
|
9
|
+
end
|
10
|
+
|
11
|
+
def has_paging?
|
12
|
+
@paging.has_key?("page")
|
13
|
+
end
|
14
|
+
|
15
|
+
def has_next_page?
|
16
|
+
@paging.has_key?("next")
|
17
|
+
end
|
18
|
+
|
19
|
+
def has_previous_page?
|
20
|
+
@paging.has_key?("previous")
|
21
|
+
end
|
22
|
+
|
23
|
+
def next_page
|
24
|
+
if has_next_page?
|
25
|
+
response = @connection.get(@user_key, @paging["next"])
|
26
|
+
if response && response.body
|
27
|
+
@resources = response.body[@resource_name].map do |record|
|
28
|
+
SifiApi.const_get(@resource_name.classify).new(record, @connection, @user_key)
|
29
|
+
end
|
30
|
+
@paging = response.body["paging"]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def previous_page
|
36
|
+
if has_previous_page?
|
37
|
+
response = @connection.get(@user_key, @paging["previous"])
|
38
|
+
if response && response.body
|
39
|
+
@resources = response.body[@resource_name].map do |record|
|
40
|
+
SifiApi.const_get(@resource_name.classify).new(record, @connection, @user_key)
|
41
|
+
end
|
42
|
+
@paging = response.body["paging"]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def current_page
|
48
|
+
has_paging? ? @paging["page"] : nil
|
49
|
+
end
|
50
|
+
|
51
|
+
def page_size
|
52
|
+
has_paging? ? @paging["size"] : nil
|
53
|
+
end
|
54
|
+
|
55
|
+
def total_pages
|
56
|
+
has_paging? ? (@paging["total"].to_f/@paging["size"]).ceil : nil
|
57
|
+
end
|
58
|
+
|
59
|
+
def total_records
|
60
|
+
has_paging? ? @paging["total"] : nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def method_missing(sym, *args, &block)
|
64
|
+
if @resources.respond_to?(sym)
|
65
|
+
@resources.send(sym, *args, &block)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_s
|
70
|
+
@resources.inspect
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
data/lib/sifi_api/version.rb
CHANGED
data/lib/sifi_api.rb
CHANGED
@@ -36,6 +36,8 @@ module SifiApi
|
|
36
36
|
autoload :ReportAsset, "sifi_api/report_asset"
|
37
37
|
autoload :ReportType, "sifi_api/report_type"
|
38
38
|
autoload :Resource, "sifi_api/resource"
|
39
|
+
autoload :ResourceCollection, "sifi_api/resource_collection"
|
40
|
+
autoload :SegmentTag, "sifi_api/segment_tag"
|
39
41
|
autoload :User, "sifi_api/user"
|
40
42
|
autoload :VERSION, "sifi_api/version"
|
41
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sifiapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-20 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
16
|
-
requirement: &
|
16
|
+
requirement: &2156829200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.7.6
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2156829200
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: multi_json
|
27
|
-
requirement: &
|
27
|
+
requirement: &2156825200 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.3
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2156825200
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: activesupport
|
38
|
-
requirement: &
|
38
|
+
requirement: &2156821960 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 3.0.10
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2156821960
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: i18n
|
49
|
-
requirement: &
|
49
|
+
requirement: &2156817720 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: 0.5.0
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2156817720
|
58
58
|
description: ''
|
59
59
|
email:
|
60
60
|
- brandon@simpli.fi
|
@@ -103,6 +103,8 @@ files:
|
|
103
103
|
- lib/sifi_api/report_asset.rb
|
104
104
|
- lib/sifi_api/report_type.rb
|
105
105
|
- lib/sifi_api/resource.rb
|
106
|
+
- lib/sifi_api/resource_collection.rb
|
107
|
+
- lib/sifi_api/segment_tag.rb
|
106
108
|
- lib/sifi_api/user.rb
|
107
109
|
- lib/sifi_api/version.rb
|
108
110
|
- lib/sifiapi.rb
|
@@ -134,6 +136,7 @@ files:
|
|
134
136
|
- spec/sifi_api/report_asset_spec.rb
|
135
137
|
- spec/sifi_api/report_spec.rb
|
136
138
|
- spec/sifi_api/report_type_spec.rb
|
139
|
+
- spec/sifi_api/segment_tag_spec.rb
|
137
140
|
- spec/sifi_api/user_spec.rb
|
138
141
|
- spec/spec_helper.rb
|
139
142
|
- spec/support/resource_shared_example.rb
|
@@ -149,18 +152,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
152
|
- - ! '>='
|
150
153
|
- !ruby/object:Gem::Version
|
151
154
|
version: '0'
|
152
|
-
segments:
|
153
|
-
- 0
|
154
|
-
hash: 4076601209202194299
|
155
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
156
|
none: false
|
157
157
|
requirements:
|
158
158
|
- - ! '>='
|
159
159
|
- !ruby/object:Gem::Version
|
160
160
|
version: '0'
|
161
|
-
segments:
|
162
|
-
- 0
|
163
|
-
hash: 4076601209202194299
|
164
161
|
requirements: []
|
165
162
|
rubyforge_project:
|
166
163
|
rubygems_version: 1.8.10
|
@@ -195,6 +192,7 @@ test_files:
|
|
195
192
|
- spec/sifi_api/report_asset_spec.rb
|
196
193
|
- spec/sifi_api/report_spec.rb
|
197
194
|
- spec/sifi_api/report_type_spec.rb
|
195
|
+
- spec/sifi_api/segment_tag_spec.rb
|
198
196
|
- spec/sifi_api/user_spec.rb
|
199
197
|
- spec/spec_helper.rb
|
200
198
|
- spec/support/resource_shared_example.rb
|