masheri 0.3.10 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/masheri.rb CHANGED
@@ -9,6 +9,7 @@ require 'masheri/exceptions'
9
9
  require 'masheri/config'
10
10
 
11
11
  require 'masheri/rpc_client'
12
+ require 'masheri/rpc_client/response'
12
13
 
13
14
  require 'masheri/rest_client'
14
15
  require 'masheri/query_builder'
@@ -55,15 +55,15 @@ module Masheri
55
55
  end
56
56
 
57
57
  def all
58
- Masheri::RpcResponse.new(self)
58
+ Masheri::RpcClient::Response.new(self)
59
59
  end
60
60
 
61
61
  def find_each(&block)
62
- Masheri::RpcResponse.new(self).find_each(&block)
62
+ Masheri::RpcClient::Response.new(self).find_each(&block)
63
63
  end
64
64
 
65
65
  def first
66
- Masheri::RpcResponse.new(items(1)).to_objects.first
66
+ Masheri::RpcClient::Response.new(items(1)).to_objects.first
67
67
  end
68
68
 
69
69
  protected
@@ -1,80 +1,4 @@
1
1
  module Masheri
2
- class RpcResponse
3
- def initialize(query_builder)
4
- @query_builder = query_builder
5
- @json = query_builder.to_json
6
- end
7
-
8
- def result
9
- @json["result"]
10
- end
11
-
12
- def error
13
- @json["error"]
14
- end
15
-
16
- def items
17
- result["items"]
18
- end
19
-
20
- def to_objects
21
- items.map do |item|
22
- @query_builder.reify(item)
23
- end
24
- end
25
-
26
- def find_each(&block)
27
- to_objects.each(&block)
28
-
29
- if next_page?
30
- response = next_page!
31
- response.find_each(&block)
32
- end
33
- end
34
-
35
- def error?
36
- error.present?
37
- end
38
-
39
- def length
40
- items.length
41
- end
42
-
43
- def more_pages?
44
- current_page < total_pages
45
- end
46
-
47
- alias :next_page? :more_pages?
48
-
49
- def next_page_number
50
- current_page + 1
51
- end
52
-
53
- # Can't call Mashery too many times, or they get mad
54
- MASHERY_WAIT_TIME = 0.1
55
-
56
- def next_page!
57
- sleep(MASHERY_WAIT_TIME)
58
- RpcResponse.new(@query_builder.page(next_page_number))
59
- end
60
-
61
- def total_items
62
- result["total_items"]
63
- end
64
-
65
- def total_pages
66
- result["total_pages"]
67
- end
68
-
69
- def current_page
70
- result["current_page"]
71
- end
72
-
73
- def items_per_page
74
- result["items_per_page"]
75
- end
76
- end
77
-
78
2
  class RpcClient
79
3
  def config
80
4
  Masheri.config
@@ -0,0 +1,79 @@
1
+ module Masheri
2
+ class RpcClient
3
+ class Response
4
+ def initialize(query_builder)
5
+ @query_builder = query_builder
6
+ @json = query_builder.to_json
7
+ end
8
+
9
+ def result
10
+ @json["result"]
11
+ end
12
+
13
+ def error
14
+ @json["error"]
15
+ end
16
+
17
+ def items
18
+ result["items"]
19
+ end
20
+
21
+ def to_objects
22
+ items.map do |item|
23
+ @query_builder.reify(item)
24
+ end
25
+ end
26
+
27
+ def find_each(&block)
28
+ to_objects.each(&block)
29
+
30
+ if next_page?
31
+ response = next_page!
32
+ response.find_each(&block)
33
+ end
34
+ end
35
+
36
+ def error?
37
+ error.present?
38
+ end
39
+
40
+ def length
41
+ items.length
42
+ end
43
+
44
+ def more_pages?
45
+ current_page < total_pages
46
+ end
47
+
48
+ alias :next_page? :more_pages?
49
+
50
+ def next_page_number
51
+ current_page + 1
52
+ end
53
+
54
+ # Can't call Mashery too many times, or they get mad
55
+ MASHERY_WAIT_TIME = 0.1
56
+
57
+ def next_page!
58
+ sleep(MASHERY_WAIT_TIME)
59
+ Response.new(@query_builder.page(next_page_number))
60
+ end
61
+
62
+ def total_items
63
+ result["total_items"]
64
+ end
65
+
66
+ def total_pages
67
+ result["total_pages"]
68
+ end
69
+
70
+ def current_page
71
+ result["current_page"]
72
+ end
73
+
74
+ def items_per_page
75
+ result["items_per_page"]
76
+ end
77
+ end
78
+ end
79
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: masheri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.10
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -60,14 +60,14 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  - !ruby/object:Gem::Dependency
63
- name: jeweler
63
+ name: redcarpet
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
67
  - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
- type: :runtime
70
+ type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
@@ -76,7 +76,7 @@ dependencies:
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  - !ruby/object:Gem::Dependency
79
- name: redcarpet
79
+ name: jeweler
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
@@ -176,6 +176,7 @@ files:
176
176
  - lib/masheri/rest_client/base.rb
177
177
  - lib/masheri/rest_client/query.rb
178
178
  - lib/masheri/rpc_client.rb
179
+ - lib/masheri/rpc_client/response.rb
179
180
  - lib/masheri/service.rb
180
181
  - LICENSE.txt
181
182
  - README.md
@@ -195,7 +196,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
195
196
  version: '0'
196
197
  segments:
197
198
  - 0
198
- hash: 2820151414351842610
199
+ hash: -3229905518716207910
199
200
  required_rubygems_version: !ruby/object:Gem::Requirement
200
201
  none: false
201
202
  requirements: