loquor 0.1.1 → 0.1.2
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/CHANGELOG.md +3 -0
- data/lib/loquor.rb +3 -2
- data/lib/loquor/api_calls/index.rb +2 -2
- data/lib/loquor/api_calls/show.rb +2 -1
- data/lib/loquor/http_actions/get.rb +5 -2
- data/lib/loquor/http_actions/post.rb +6 -3
- data/lib/loquor/interactor.rb +29 -0
- data/lib/loquor/{representations.rb → interactors.rb} +3 -3
- data/lib/loquor/representation.rb +29 -18
- data/lib/loquor/version.rb +1 -1
- data/loquor.gemspec +1 -1
- data/test/api_calls/index_test.rb +17 -0
- data/test/api_calls/show_test.rb +13 -0
- data/test/http_actions/get_test.rb +1 -0
- data/test/http_actions/post_test.rb +6 -0
- data/test/interactor_test.rb +39 -0
- data/test/{representations_test.rb → interactors_test.rb} +1 -1
- data/test/representation_test.rb +7 -35
- metadata +12 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a891916202c44567d39b1b214f39452edd263796
|
4
|
+
data.tar.gz: 815fbff4daaacbf2dc47e8ed248e6d2978338c68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99a10b205e5c4597d6405b29faeb2180a04bb5f59afda111926f73d28070d7f79deed65aef6eb02806c04e277e46146ddd70924c2079881345e5db4ad3d4a692
|
7
|
+
data.tar.gz: 2890c5bf49c393a1c0b46113c903eface6b5387637f945935b7e739152a745fa5671f17ea8a9a518e698dfd02cb2d2137b5f936729090bc9d72810b80ac1f2f9
|
data/CHANGELOG.md
ADDED
data/lib/loquor.rb
CHANGED
@@ -5,6 +5,7 @@ require 'filum'
|
|
5
5
|
require "loquor/version"
|
6
6
|
require "loquor/configuration"
|
7
7
|
require "loquor/client"
|
8
|
+
require 'loquor/interactor'
|
8
9
|
require 'loquor/representation'
|
9
10
|
|
10
11
|
require 'loquor/api_call'
|
@@ -12,7 +13,7 @@ require "loquor/http_action"
|
|
12
13
|
|
13
14
|
module Loquor
|
14
15
|
|
15
|
-
|
16
|
+
Interactors = {
|
16
17
|
"GroupDiscussion" => "/group_discussions",
|
17
18
|
"GroupDiscussionPost" => "/group_discussion_posts",
|
18
19
|
"MediaFile" => "/media_files",
|
@@ -46,4 +47,4 @@ module Loquor
|
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
49
|
-
require 'loquor/
|
50
|
+
require 'loquor/interactors'
|
@@ -28,7 +28,7 @@ module Loquor
|
|
28
28
|
begin
|
29
29
|
results = Loquor.get("#{generate_url}&page=#{page}&per=#{per}")
|
30
30
|
results.each do |result|
|
31
|
-
yield result
|
31
|
+
yield Representation.new(result)
|
32
32
|
end
|
33
33
|
page += 1
|
34
34
|
end while(results.size == per)
|
@@ -38,7 +38,7 @@ module Loquor
|
|
38
38
|
|
39
39
|
def results
|
40
40
|
if @results.nil?
|
41
|
-
@results = Loquor.get(generate_url)
|
41
|
+
@results = Loquor.get(generate_url).map {|obj| Representation.new(obj)}
|
42
42
|
end
|
43
43
|
@results
|
44
44
|
end
|
@@ -9,7 +9,7 @@ module Loquor
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def get
|
12
|
-
@config.logger.info "Making GET request to: #{
|
12
|
+
@config.logger.info "Making GET request to: #{full_url}"
|
13
13
|
response = JSON.parse(signed_request.execute)
|
14
14
|
@config.logger.info "Signed request executed. Response: #{response}"
|
15
15
|
response
|
@@ -17,8 +17,11 @@ module Loquor
|
|
17
17
|
|
18
18
|
private
|
19
19
|
def request
|
20
|
-
full_url = "#{@config.endpoint}#{@url}"
|
21
20
|
RestClient::Request.new(url: full_url, method: :get)
|
22
21
|
end
|
22
|
+
|
23
|
+
def full_url
|
24
|
+
"#{@config.endpoint}#{@url}"
|
25
|
+
end
|
23
26
|
end
|
24
27
|
end
|
@@ -10,10 +10,10 @@ module Loquor
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def post
|
13
|
-
@config.logger.info "Making POST request to: #{
|
13
|
+
@config.logger.info "Making POST request to: #{full_url}"
|
14
14
|
response = JSON.parse(signed_request.execute)
|
15
15
|
@config.logger.info "Signed request executed. Response: #{response}"
|
16
|
-
response
|
16
|
+
Representation.new(response)
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
@@ -25,12 +25,15 @@ module Loquor
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def request
|
28
|
-
full_url = "#{@config.endpoint}#{@url}"
|
29
28
|
RestClient::Request.new(url: full_url,
|
30
29
|
accept: :json,
|
31
30
|
payload: @payload.to_json,
|
32
31
|
headers: {'Content-type' => 'application/json'},
|
33
32
|
method: :post)
|
34
33
|
end
|
34
|
+
|
35
|
+
def full_url
|
36
|
+
"#{@config.endpoint}#{@url}"
|
37
|
+
end
|
35
38
|
end
|
36
39
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Loquor
|
2
|
+
module Interactor
|
3
|
+
module ClassMethods
|
4
|
+
[:find, :find_each, :where, :create].each do |proxy|
|
5
|
+
define_method proxy do |*args, &block|
|
6
|
+
new.send proxy, *args, &block
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module InstanceMethods
|
12
|
+
def find(id)
|
13
|
+
ApiCall::Show.new(self.class.path, id).execute
|
14
|
+
end
|
15
|
+
|
16
|
+
def find_each(&block)
|
17
|
+
ApiCall::Index.new(self.class.path).find_each(&block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def where(*args)
|
21
|
+
ApiCall::Index.new(self.class.path).where(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
def create(payload)
|
25
|
+
ApiCall::Create.new(self.class.path, payload).execute
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
Loquor::
|
1
|
+
Loquor::Interactors.each do |name, path|
|
2
2
|
klass = Class.new(Object) do
|
3
|
-
extend Loquor::
|
4
|
-
include Loquor::
|
3
|
+
extend Loquor::Interactor::ClassMethods
|
4
|
+
include Loquor::Interactor::InstanceMethods
|
5
5
|
|
6
6
|
instance_eval <<-EOS
|
7
7
|
def path
|
@@ -1,29 +1,40 @@
|
|
1
1
|
module Loquor
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
define_method proxy do |*args, &block|
|
6
|
-
new.send proxy, *args, &block
|
7
|
-
end
|
8
|
-
end
|
2
|
+
class Representation
|
3
|
+
def initialize(hash)
|
4
|
+
@hash = hash
|
9
5
|
end
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
def ==(other)
|
8
|
+
if other.is_a?(Representation)
|
9
|
+
@hash == other.get_instance_variable(:@hash)
|
10
|
+
elsif other.is_a?(Hash)
|
11
|
+
@hash == other
|
12
|
+
else
|
13
|
+
false
|
14
14
|
end
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def [](key)
|
18
|
+
@hash[key]
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
def method_missing(name, *args)
|
22
|
+
if @hash.has_key?(name)
|
23
|
+
@hash[name]
|
24
|
+
else
|
25
|
+
super
|
22
26
|
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
23
30
|
|
24
|
-
|
25
|
-
|
26
|
-
|
31
|
+
class Hash
|
32
|
+
alias_method :hash_equals, :==
|
33
|
+
def ==(other)
|
34
|
+
if other.is_a?(Loquor::Representation)
|
35
|
+
other == self
|
36
|
+
else
|
37
|
+
hash_equals(other)
|
27
38
|
end
|
28
39
|
end
|
29
40
|
end
|
data/lib/loquor/version.rb
CHANGED
data/loquor.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency 'filum', '0.0.
|
21
|
+
spec.add_dependency 'filum', '0.0.2'
|
22
22
|
spec.add_dependency 'rest-client', '1.6.7'
|
23
23
|
spec.add_dependency "api-auth", "1.0.3"
|
24
24
|
|
@@ -93,5 +93,22 @@ module Loquor
|
|
93
93
|
Loquor.expects(:get).with("http://foobar.com?&page=2&per=200").returns([])
|
94
94
|
searcher.find_each {}
|
95
95
|
end
|
96
|
+
|
97
|
+
def test_find_each_objects_are_representations
|
98
|
+
searcher = ApiCall::Index.new('')
|
99
|
+
Loquor.expects(:get).returns([{'id' => 8}, {'id' => 10}])
|
100
|
+
searcher.find_each do |rep|
|
101
|
+
assert rep.is_a?(Representation)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_objects_are_representations
|
106
|
+
index = ApiCall::Index.new("")
|
107
|
+
Loquor.stubs(get: [{foo: 'bar'}, {cat: 'dog'}])
|
108
|
+
results = index.send(:results)
|
109
|
+
assert results.is_a?(Array)
|
110
|
+
assert results[0].is_a?(Representation)
|
111
|
+
assert results[1].is_a?(Representation)
|
112
|
+
end
|
96
113
|
end
|
97
114
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Loquor
|
4
|
+
class ApiCall::ShowTest < Minitest::Test
|
5
|
+
|
6
|
+
def test_response_is_a_representation
|
7
|
+
show = ApiCall::Show.new("", 1)
|
8
|
+
Loquor.stubs(get: {foo: 'bar'}.to_json)
|
9
|
+
response = show.execute
|
10
|
+
assert response.is_a?(Representation)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -46,6 +46,12 @@ module Loquor
|
|
46
46
|
posts.send(:signed_request)
|
47
47
|
end
|
48
48
|
|
49
|
+
def test_response_is_a_representation
|
50
|
+
posts = HttpAction::Post.new("", {}, deps)
|
51
|
+
posts.stubs(signed_request: mock(execute: {foo: 'bar'}.to_json))
|
52
|
+
response = posts.post
|
53
|
+
assert response.is_a?(Representation)
|
54
|
+
end
|
49
55
|
end
|
50
56
|
end
|
51
57
|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Loquor
|
4
|
+
class InteractorTest < Minitest::Test
|
5
|
+
class FoobarInteractor
|
6
|
+
extend Interactor::ClassMethods
|
7
|
+
include Interactor::InstanceMethods
|
8
|
+
|
9
|
+
def self.path
|
10
|
+
"/foobar"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_find_should_get_correct_path_with_simple_path
|
15
|
+
id = 8
|
16
|
+
Loquor.expects(:get).with("/foobar/#{id}")
|
17
|
+
FoobarInteractor.find(id)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_find_each_should_get_correct_path
|
21
|
+
Loquor.expects(:get).with("/foobar?&page=1&per=200").returns([])
|
22
|
+
FoobarInteractor.find_each
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_find_each_should_yield_block
|
26
|
+
Loquor.expects(:get).returns([{id: 1}])
|
27
|
+
ids = []
|
28
|
+
FoobarInteractor.find_each do |json|
|
29
|
+
ids << json['id']
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_where_should_get_correct_path_with_simple_path
|
34
|
+
email = "foobar"
|
35
|
+
Loquor.expects(:get).with("/foobar?email=#{email}").returns([])
|
36
|
+
FoobarInteractor.where(email: email).to_a
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/test/representation_test.rb
CHANGED
@@ -1,43 +1,15 @@
|
|
1
1
|
require File.expand_path('../test_helper', __FILE__)
|
2
2
|
|
3
3
|
module Loquor
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def build_path
|
10
|
-
"/foobar"
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.path
|
14
|
-
"/foobar"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_find_should_get_correct_path_with_simple_path
|
19
|
-
id = 8
|
20
|
-
Loquor.expects(:get).with("/foobar/#{id}")
|
21
|
-
FoobarRepresentation.find(id)
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_find_each_should_get_correct_path
|
25
|
-
Loquor.expects(:get).with("/foobar?&page=1&per=200").returns([])
|
26
|
-
FoobarRepresentation.find_each
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_find_each_should_yield_block
|
30
|
-
Loquor.expects(:get).returns([{id: 1}])
|
31
|
-
ids = []
|
32
|
-
FoobarRepresentation.find_each do |json|
|
33
|
-
ids << json['id']
|
34
|
-
end
|
4
|
+
class RepresenationTest < Minitest::Test
|
5
|
+
def test_is_accessible_as_a_hash
|
6
|
+
representation = Representation.new({foo: "bar"})
|
7
|
+
assert_equal "bar", representation[:foo]
|
35
8
|
end
|
36
9
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
40
|
-
FoobarRepresentation.where(email: email).to_a
|
10
|
+
def test_hash_keys_are_accessible_via_methods
|
11
|
+
representation = Representation.new({foo: "bar"})
|
12
|
+
assert_equal "bar", representation.foo
|
41
13
|
end
|
42
14
|
end
|
43
15
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loquor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Walker
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.0.
|
19
|
+
version: 0.0.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.0.
|
26
|
+
version: 0.0.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rest-client
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,6 +116,7 @@ extensions: []
|
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
118
|
- .gitignore
|
119
|
+
- CHANGELOG.md
|
119
120
|
- CONTRIBUTING.md
|
120
121
|
- Gemfile
|
121
122
|
- LICENCE.md
|
@@ -131,18 +132,21 @@ files:
|
|
131
132
|
- lib/loquor/http_action.rb
|
132
133
|
- lib/loquor/http_actions/get.rb
|
133
134
|
- lib/loquor/http_actions/post.rb
|
135
|
+
- lib/loquor/interactor.rb
|
136
|
+
- lib/loquor/interactors.rb
|
134
137
|
- lib/loquor/representation.rb
|
135
|
-
- lib/loquor/representations.rb
|
136
138
|
- lib/loquor/version.rb
|
137
139
|
- loquor.gemspec
|
138
140
|
- test/api_calls/index_test.rb
|
141
|
+
- test/api_calls/show_test.rb
|
139
142
|
- test/client_test.rb
|
140
143
|
- test/configuration_test.rb
|
141
144
|
- test/http_action_test.rb
|
142
145
|
- test/http_actions/get_test.rb
|
143
146
|
- test/http_actions/post_test.rb
|
147
|
+
- test/interactor_test.rb
|
148
|
+
- test/interactors_test.rb
|
144
149
|
- test/representation_test.rb
|
145
|
-
- test/representations_test.rb
|
146
150
|
- test/test_helper.rb
|
147
151
|
homepage: https://www.meducation.net
|
148
152
|
licenses:
|
@@ -170,12 +174,14 @@ specification_version: 4
|
|
170
174
|
summary: This library dispatches requests to Meducation
|
171
175
|
test_files:
|
172
176
|
- test/api_calls/index_test.rb
|
177
|
+
- test/api_calls/show_test.rb
|
173
178
|
- test/client_test.rb
|
174
179
|
- test/configuration_test.rb
|
175
180
|
- test/http_action_test.rb
|
176
181
|
- test/http_actions/get_test.rb
|
177
182
|
- test/http_actions/post_test.rb
|
183
|
+
- test/interactor_test.rb
|
184
|
+
- test/interactors_test.rb
|
178
185
|
- test/representation_test.rb
|
179
|
-
- test/representations_test.rb
|
180
186
|
- test/test_helper.rb
|
181
187
|
has_rdoc:
|