loquor 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f90da533241c34e6048170796622c39625586db
4
- data.tar.gz: 149b90328f1f832b2e232ffac78cbd061345ce66
3
+ metadata.gz: f196e20d696c7441d01f41d46143bbe63b4f8f08
4
+ data.tar.gz: 93d9758a04a1a83d08d63d7643532e1c223d3892
5
5
  SHA512:
6
- metadata.gz: 3d99385acd26254da7e23c86af5928c62f1d918de78cfe9ebfc2f8df3ad29a24975e3dd3659f1207d1ee542bdc74159872160a42354d128cbe278ecb8cee9606
7
- data.tar.gz: 3fcdc72de7f80141f9cae06ba6795e589c65405065b3cff52b8f258da54076fa8d22d4d68419d7534b77d71fe3dae7b8ed0e7ab4c58071d4f0eb80d5cd1b7a3c
6
+ metadata.gz: 5d3000cbd0cd13292723494b7332f67a04221cf169e8784530d4410e3e4978382b66c79d4480f8b269c5868fd05030f23158380586fa3c7f0a0a0fef651ef1eb
7
+ data.tar.gz: 340af6b04809d23c223fd03e76cba56984495ab790cf7ef3a6a0f27d25958b9aaca3f975b65ae6eeebd466e4b4d88b72493abeb61752173919440428a854c57b
data/CONTRIBUTING.md CHANGED
@@ -3,14 +3,12 @@
3
3
  First of all, **thank you** for contributing to this library!
4
4
 
5
5
  ## Issues
6
- Please file issues on the [GitHub issues list](https://github.com/meducation/propono/issues) and give as much detail as possible.
6
+ Please file issues on the [GitHub issues list](https://github.com/meducation/loquor/issues) and give as much detail as possible.
7
7
 
8
8
  ## Features / Pull Requests
9
9
 
10
10
  If you want a feature implemented, the best way to get it done is to submit a pull request that implements it. Please make sure it has tests.
11
11
 
12
- To get the implementation tests to run, you'll need to create a `test/config.yml` file. There's an example to get you started.
13
-
14
12
  You can run the tests with:
15
13
 
16
14
  ```
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # Loquor - Meducation API Dispatcher
1
+ # Loquor
2
2
 
3
3
  [![Build Status](https://travis-ci.org/meducation/loquor.png)](https://travis-ci.org/meducation/loquor)
4
4
  [![Dependencies](https://gemnasium.com/meducation/loquor.png?travis)](https://gemnasium.com/meducation/loquor)
5
5
  [![Code Climate](https://codeclimate.com/github/meducation/loquor.png)](https://codeclimate.com/github/meducation/loquor)
6
6
 
7
- Handles calls to the Meducation API via an ActiveRecord-style interface
7
+ Loquor handles calls to an API via an ActiveRecord-style interface. It is currently configured for the Meducation API but could easily be changed for any other API. It allows you to access show/index/update/create actions with simple calls like `MediaFile.find(8)`, without having to worry about HTTP, JSON or anything else.
8
8
 
9
9
  ## Installation
10
10
 
@@ -18,10 +18,9 @@ And then execute:
18
18
 
19
19
  $ bundle
20
20
 
21
-
22
21
  ## Usage
23
22
 
24
- You will want to set up some configuration variables.
23
+ To get going, you will want to set up some configuration variables.
25
24
  ``` ruby
26
25
  Loquor.config do |config|
27
26
  config.access_id = "Username"
@@ -30,25 +29,46 @@ Loquor.config do |config|
30
29
  end
31
30
  ```
32
31
 
33
- Now you can make requests to get, create, update, destroy and list a range of objects, like this:
32
+ If you're not using this for Meducation, then edit the [mappings here](https://github.com/meducation/loquor/blob/master/lib/loquor.rb#L16).
33
+
34
+ Now you can make requests to get, create, update, destroy and list a range of objects, likein the same way you would interactive with an ActiveREcord object.
35
+
36
+ For example, you can get search objects using where:
34
37
 
35
38
  ```ruby
36
- Loquor::User.where(email: "jeremy@meducation.net").where(name: "Jeremy").each do |user|
39
+ items = Loquor::User.where(email: "jeremy@meducation.net").where(name: "Jeremy")
40
+ # => [{id: 2, name: "Jeremy Walker"}, {id: 3, name: "Malcolm Landon"}]
41
+ ```
42
+
43
+ Items responds to all the enumeration methods on Array. e.g.
44
+
45
+ ```ruby
46
+ items.each do |user|
37
47
  p "The user with id ##{user['id']} is #{user['name']}."
38
48
  end
49
+ ```
39
50
 
40
- Loquor::User.find(2) # => {id: 2, name: "Jeremy Walker"}
51
+ The returned objects can be accessed as hashes (using either strings or symbols), or using dot notaton. e.g.:
41
52
 
42
- Loquor::User.create(name: "Jeremy Walker", email: "jeremy@meducation.net") # => {id: 2, name: "Jeremy Walker", email "jeremy@meducation.net"}
53
+ ```ruby
54
+ user = User.where(foo: 'bar').first
55
+ user.name
56
+ user['name']
57
+ user[:name]
43
58
  ```
44
59
 
45
- ### Supported Objects
60
+ You can use `find` and `find_each` (which sends requests to the API in batches of 200)
61
+ ```ruby
62
+ Loquor::User.find(2) # => {id: 2, name: "Jeremy Walker"}
63
+ Loquor::User.find_each do |user|
64
+ # ...
65
+ end
66
+ ```
46
67
 
47
- The following are currently endpoints are supported:
48
- * Group Discussions
49
- * Group Discussion Posts
50
- * Media Files
51
- * Users
68
+ You can also create users using the normal ActiveRecord method:
69
+ ```ruby
70
+ Loquor::User.create(name: "Jeremy Walker", email: "jeremy@meducation.net") # => {id: 2, name: "Jeremy Walker", email "jeremy@meducation.net"}
71
+ ```
52
72
 
53
73
  ### Is it any good?
54
74
 
data/Rakefile CHANGED
@@ -4,11 +4,4 @@ require 'rake/testtask'
4
4
  Rake::TestTask.new do |t|
5
5
  t.pattern = "test/**/*_test.rb"
6
6
  end
7
-
8
- namespace :test do
9
- Rake::TestTask.new(:local) do |t|
10
- t.pattern = "test/{components/,services/,helpers/,}*_test.rb"
11
- end
12
- end
13
-
14
7
  task default: :test
@@ -1,7 +1,8 @@
1
1
  module Loquor
2
2
  class ApiCall
3
- def initialize(path)
4
- @path = path
3
+ attr_reader :klass
4
+ def initialize(klass)
5
+ @klass = klass
5
6
  end
6
7
  end
7
8
  end
@@ -1,13 +1,13 @@
1
1
  module Loquor
2
2
  class ApiCall::Create < ApiCall
3
3
 
4
- def initialize(path, payload)
5
- super(path)
4
+ def initialize(klass, payload)
5
+ super(klass)
6
6
  @payload = payload
7
7
  end
8
8
 
9
9
  def execute
10
- Loquor.post(@path, @payload)
10
+ klass.new Loquor.post(klass.path, @payload)
11
11
  end
12
12
  end
13
13
  end
@@ -3,8 +3,8 @@ module Loquor
3
3
 
4
4
  attr_reader :criteria
5
5
 
6
- def initialize(path)
7
- super(path)
6
+ def initialize(klass)
7
+ super(klass)
8
8
  @criteria = {}
9
9
  end
10
10
 
@@ -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 Representation.new(result)
31
+ yield klass.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).map {|obj| Representation.new(obj)}
41
+ @results = Loquor.get(generate_url).map {|obj| klass.new(obj)}
42
42
  end
43
43
  @results
44
44
  end
@@ -53,7 +53,7 @@ module Loquor
53
53
  raise LoquorError.new("Filter values must be strings or arrays.")
54
54
  end
55
55
  }.join("&")
56
- "#{@path}?#{query_string}"
56
+ "#{klass.path}?#{query_string}"
57
57
  end
58
58
  end
59
59
  end
@@ -1,14 +1,14 @@
1
1
  module Loquor
2
2
  class ApiCall::Show < ApiCall
3
3
 
4
- def initialize(path, id)
5
- super(path)
4
+ def initialize(klass, id)
5
+ super(klass)
6
6
  @id = id
7
7
  end
8
8
 
9
9
  def execute
10
- obj = Loquor.get("#{@path}/#{@id}")
11
- Representation.new(obj)
10
+ obj = Loquor.get("#{klass.path}/#{@id}")
11
+ @klass.new(obj)
12
12
  end
13
13
  end
14
14
  end
@@ -13,7 +13,7 @@ module Loquor
13
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
- Representation.new(response)
16
+ Resource.new(response)
17
17
  end
18
18
 
19
19
  private
@@ -17,7 +17,8 @@ Loquor::Interactors.each do |name, path|
17
17
  # Create base modules
18
18
  const = Loquor
19
19
  name_parts.each do |name_part|
20
- const.const_set name_part, Module unless const.const_defined?(name_part)
20
+ const.const_set(name_part, Module.new) unless const.const_defined?(name_part)
21
+ const = const.const_get(name_part)
21
22
  end
22
23
 
23
24
  # Define the actual klass at the right point
@@ -1,14 +1,14 @@
1
1
  module Loquor
2
- class RepresentationHashKeyMissingError < LoquorError
3
-
2
+ class ObjectHashKeyMissingError < LoquorError
4
3
  end
5
- class Representation
4
+
5
+ class ObjectHash
6
6
  def initialize(hash)
7
7
  @hash = hash
8
8
  end
9
9
 
10
10
  def ==(other)
11
- if other.is_a?(Representation)
11
+ if other.is_a?(ObjectHash)
12
12
  @hash == other.get_instance_variable(:@hash)
13
13
  elsif other.is_a?(Hash)
14
14
  @hash == other
@@ -19,13 +19,13 @@ module Loquor
19
19
 
20
20
  def [](key)
21
21
  fetch_indescriminately(key)
22
- rescue RepresentationHashKeyMissingError
22
+ rescue ObjectHashKeyMissingError
23
23
  nil
24
24
  end
25
25
 
26
26
  def method_missing(name, *args)
27
27
  fetch_indescriminately(name, *args)
28
- rescue RepresentationHashKeyMissingError
28
+ rescue ObjectHashKeyMissingError
29
29
  @hash.send(name, *args)
30
30
  end
31
31
 
@@ -39,7 +39,7 @@ module Loquor
39
39
  elsif @hash.has_key?(name.to_s.to_sym)
40
40
  @hash[name.to_s.to_sym]
41
41
  else
42
- raise RepresentationHashKeyMissingError.new
42
+ raise ObjectHashKeyMissingError.new
43
43
  end
44
44
  end
45
45
  end
@@ -48,7 +48,7 @@ end
48
48
  class Hash
49
49
  alias_method :hash_equals, :==
50
50
  def ==(other)
51
- if other.is_a?(Loquor::Representation)
51
+ if other.is_a?(Loquor::ObjectHash)
52
52
  other == self
53
53
  else
54
54
  hash_equals(other)
@@ -0,0 +1,36 @@
1
+ module Loquor
2
+ class Resource
3
+
4
+ def initialize(data)
5
+ @data = ObjectHash.new(data)
6
+ end
7
+
8
+ def method_missing(name, *args)
9
+ @data[name]
10
+ end
11
+
12
+ def self.path=(path)
13
+ @path = path
14
+ end
15
+
16
+ def self.path
17
+ @path
18
+ end
19
+
20
+ def self.find(id)
21
+ ApiCall::Show.new(self, id).execute
22
+ end
23
+
24
+ def self.find_each(&block)
25
+ ApiCall::Index.new(self).find_each(&block)
26
+ end
27
+
28
+ def self.where(*args)
29
+ ApiCall::Index.new(self).where(*args)
30
+ end
31
+
32
+ def self.create(payload)
33
+ ApiCall::Create.new(self, payload).execute
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,28 @@
1
+ module Loquor
2
+ module ResourceMock
3
+
4
+ def attributes
5
+ @attributes
6
+ end
7
+
8
+ def attributes=(attrs)
9
+ @attributes = attrs
10
+ end
11
+
12
+ def sample
13
+ self.new(attributes)
14
+ end
15
+
16
+ def find(id)
17
+ self.new(attributes.merge(id: id))
18
+ end
19
+
20
+ def where(*args)
21
+ [ find(1), find(2) ]
22
+ end
23
+
24
+ def create(attrs)
25
+ self.new(attrs)
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Loquor
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/loquor.rb CHANGED
@@ -5,26 +5,15 @@ require 'filum'
5
5
  require "loquor/version"
6
6
  require "loquor/configuration"
7
7
  require "loquor/client"
8
- require 'loquor/interactor'
9
- require 'loquor/representation'
8
+ require 'loquor/object_hash'
9
+ require 'loquor/resource'
10
+ require 'loquor/resource_mock'
10
11
 
11
12
  require 'loquor/api_call'
12
13
  require "loquor/http_action"
13
14
 
14
15
  module Loquor
15
16
 
16
- Interactors = {
17
- "GroupDiscussion" => "/group_discussions",
18
- "GroupDiscussionPost" => "/group_discussion_posts",
19
- "MediaFile" => "/media_files",
20
- "MeshHeading" => "/mesh_headings",
21
- "Mnemonic" => "/mnemonics",
22
- "PremiumTutorial" => "/premium_tutorials",
23
- "Partner" => "/partners",
24
- "SyllabusItem" => "/syllabus_items",
25
- "User" => "/users"
26
- }
27
-
28
17
  def self.config
29
18
  if block_given?
30
19
  yield loquor.config
@@ -47,5 +36,3 @@ module Loquor
47
36
  @loquor ||= Client.new
48
37
  end
49
38
  end
50
-
51
- require 'loquor/interactors'
@@ -2,53 +2,59 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Loquor
4
4
  class ApiCall::IndexTest < Minitest::Test
5
+ def resource
6
+ r = Resource
7
+ r.stubs(path: "http://foobar.com")
8
+ r
9
+ end
10
+
5
11
  def test_where_sets_criteria
6
12
  criteria = {genre: 'Animation'}
7
- searcher = ApiCall::Index.new('').where(criteria)
13
+ searcher = ApiCall::Index.new(resource).where(criteria)
8
14
  assert_equal({genre: 'Animation'}, searcher.criteria)
9
15
  end
10
16
 
11
17
  def test_where_merges_criteria
12
18
  criteria1 = {genre: 'Animation'}
13
19
  criteria2 = {foobar: 'Cat'}
14
- searcher = ApiCall::Index.new('').where(criteria1).where(criteria2)
20
+ searcher = ApiCall::Index.new(resource).where(criteria1).where(criteria2)
15
21
  assert_equal({genre: 'Animation', foobar: 'Cat'}, searcher.criteria)
16
22
  end
17
23
 
18
24
  def test_where_overrides_criteria_with_same_key
19
25
  criteria1 = {genre: 'Animation'}
20
26
  criteria2 = {genre: 'Action'}
21
- searcher = ApiCall::Index.new('').where(criteria1).where(criteria2)
27
+ searcher = ApiCall::Index.new(resource).where(criteria1).where(criteria2)
22
28
  assert_equal({genre: "Action"}, searcher.criteria)
23
29
  end
24
30
 
25
31
  def test_where_gets_correct_url
26
- searcher = ApiCall::Index.new('').where(name: 'Star Wars')
32
+ searcher = ApiCall::Index.new(resource).where(name: 'Star Wars')
27
33
  assert searcher.send(:generate_url).include? "?name=Star%20Wars"
28
34
  end
29
35
 
30
36
  def test_where_works_with_array_in_a_hash
31
37
  criteria = {thing: ['foo', 'bar']}
32
- searcher = ApiCall::Index.new('').where(criteria)
38
+ searcher = ApiCall::Index.new(resource).where(criteria)
33
39
  assert_equal criteria, searcher.criteria
34
40
  end
35
41
 
36
42
  def test_that_iterating_calls_results
37
- searcher = ApiCall::Index.new('').where(name: "star_wars")
43
+ searcher = ApiCall::Index.new(resource).where(name: "star_wars")
38
44
  searcher.expects(results: [])
39
45
  searcher.each { }
40
46
  end
41
47
 
42
48
  def test_that_iterating_calls_each
43
49
  Loquor.expects(:get).returns([{id: 8, name: "Star Wars"}])
44
- searcher = ApiCall::Index.new('').where(name: "star_wars")
50
+ searcher = ApiCall::Index.new(resource).where(name: "star_wars")
45
51
  searcher.send(:results).expects(:each)
46
52
  searcher.each { }
47
53
  end
48
54
 
49
55
  def test_that_select_calls_each
50
56
  Loquor.expects(:get).returns([{id: 8, name: "Star Wars"}])
51
- searcher = ApiCall::Index.new('').where(name: "star_wars")
57
+ searcher = ApiCall::Index.new(resource).where(name: "star_wars")
52
58
  searcher.send(:results).expects(:select)
53
59
  searcher.select { }
54
60
  end
@@ -57,37 +63,37 @@ module Loquor
57
63
  expected_results = [{id: 8, name: "Star Wars"}]
58
64
  Loquor.expects(:get).returns(expected_results)
59
65
 
60
- searcher = ApiCall::Index.new('').where(name: "star_wars")
61
- searcher.to_a
62
- assert_equal expected_results, searcher.instance_variable_get("@results")
66
+ resources = ApiCall::Index.new(resource).where(name: "star_wars").to_a
67
+ assert_equal 8, resources.first.id
68
+ assert_equal 'Star Wars', resources.first.name
63
69
  end
64
70
 
65
71
  def test_search_should_create_a_results_object
66
72
  Loquor.expects(:get).returns([{id: 8, name: "Star Wars"}])
67
- searcher = ApiCall::Index.new('').where(name: "star_wars")
73
+ searcher = ApiCall::Index.new(resource).where(name: "star_wars")
68
74
  searcher.to_a
69
75
  assert Array, searcher.instance_variable_get("@results").class
70
76
  end
71
77
 
72
78
  def test_find_each_calls_block_for_each_item
73
- searcher = ApiCall::Index.new('')
79
+ searcher = ApiCall::Index.new(Resource)
74
80
  Loquor.expects(:get).returns([{'id' => 8}, {'id' => 10}])
75
81
 
76
82
  ids = []
77
83
  searcher.find_each do |json|
78
- ids << json['id']
84
+ ids << json.id
79
85
  end
80
86
  assert_equal [8,10], ids
81
87
  end
82
88
 
83
89
  def test_find_each_limits_to_200
84
- searcher = ApiCall::Index.new('http://foobar.com')
90
+ searcher = ApiCall::Index.new(resource)
85
91
  Loquor.expects(:get).with("http://foobar.com?&page=1&per=200").returns([])
86
92
  searcher.find_each {}
87
93
  end
88
94
 
89
95
  def test_find_each_runs_multiple_times
90
- searcher = ApiCall::Index.new('http://foobar.com')
96
+ searcher = ApiCall::Index.new(resource)
91
97
  results = 200.times.map{""}
92
98
  Loquor.expects(:get).with("http://foobar.com?&page=1&per=200").returns(results)
93
99
  Loquor.expects(:get).with("http://foobar.com?&page=2&per=200").returns([])
@@ -95,20 +101,20 @@ module Loquor
95
101
  end
96
102
 
97
103
  def test_find_each_objects_are_representations
98
- searcher = ApiCall::Index.new('')
104
+ searcher = ApiCall::Index.new(resource)
99
105
  Loquor.expects(:get).returns([{'id' => 8}, {'id' => 10}])
100
106
  searcher.find_each do |rep|
101
- assert rep.is_a?(Representation)
107
+ assert rep.is_a?(Resource)
102
108
  end
103
109
  end
104
110
 
105
111
  def test_objects_are_representations
106
- index = ApiCall::Index.new("")
112
+ index = ApiCall::Index.new(Resource)
107
113
  Loquor.stubs(get: [{foo: 'bar'}, {cat: 'dog'}])
108
114
  results = index.send(:results)
109
115
  assert results.is_a?(Array)
110
- assert results[0].is_a?(Representation)
111
- assert results[1].is_a?(Representation)
116
+ assert results[0].is_a?(Resource)
117
+ assert results[1].is_a?(Resource)
112
118
  end
113
119
  end
114
120
  end
@@ -4,10 +4,10 @@ module Loquor
4
4
  class ApiCall::ShowTest < Minitest::Test
5
5
 
6
6
  def test_response_is_a_representation
7
- show = ApiCall::Show.new("", 1)
7
+ show = ApiCall::Show.new(Resource, 1)
8
8
  Loquor.stubs(get: {foo: 'bar'}.to_json)
9
9
  response = show.execute
10
- assert response.is_a?(Representation)
10
+ assert response.is_a?(Resource)
11
11
  end
12
12
  end
13
13
  end
@@ -20,7 +20,7 @@ module Loquor
20
20
  json = output.to_json
21
21
  posts = HttpAction::Post.new("", {}, deps)
22
22
  posts.expects(signed_request: mock(execute: json))
23
- assert_equal output, posts.post
23
+ assert_equal 'bar', posts.post.foo
24
24
  end
25
25
 
26
26
  def test_request_is_generated_correctly
@@ -50,7 +50,7 @@ module Loquor
50
50
  posts = HttpAction::Post.new("", {}, deps)
51
51
  posts.stubs(signed_request: mock(execute: {foo: 'bar'}.to_json))
52
52
  response = posts.post
53
- assert response.is_a?(Representation)
53
+ assert response.is_a?(Resource)
54
54
  end
55
55
  end
56
56
  end
@@ -1,29 +1,29 @@
1
1
  require File.expand_path('../test_helper', __FILE__)
2
2
 
3
3
  module Loquor
4
- class RepresenationTest < Minitest::Test
4
+ class ObjectHashTest < Minitest::Test
5
5
  def test_is_accessible_as_a_hash
6
- representation = Representation.new({foo: "bar"})
6
+ representation = ObjectHash.new({foo: "bar"})
7
7
  assert_equal "bar", representation[:foo]
8
8
  end
9
9
 
10
10
  def test_hash_symbol_keys_are_accessible_as_strings
11
- representation = Representation.new({foo: "bar"})
11
+ representation = ObjectHash.new({foo: "bar"})
12
12
  assert_equal "bar", representation["foo"]
13
13
  end
14
14
 
15
15
  def test_hash_string_keys_are_accessible_as_symbols
16
- representation = Representation.new({"foo" => "bar"})
16
+ representation = ObjectHash.new({"foo" => "bar"})
17
17
  assert_equal "bar", representation[:foo]
18
18
  end
19
19
 
20
20
  def test_hash_keys_are_accessible_as_orignals
21
- representation = Representation.new({1 => "bar"})
21
+ representation = ObjectHash.new({1 => "bar"})
22
22
  assert_equal "bar", representation[1]
23
23
  end
24
24
 
25
25
  def test_hash_keys_are_accessible_via_methods
26
- representation = Representation.new({foo: "bar"})
26
+ representation = ObjectHash.new({foo: "bar"})
27
27
  assert_equal "bar", representation.foo
28
28
  end
29
29
  end
@@ -1,31 +1,26 @@
1
1
  require File.expand_path('../test_helper', __FILE__)
2
2
 
3
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
4
+ class ResourceTest < Minitest::Test
5
+ class Foobar < Resource
6
+ self.path = "/foobar"
12
7
  end
13
8
 
14
9
  def test_find_should_get_correct_path_with_simple_path
15
10
  id = 8
16
11
  Loquor.expects(:get).with("/foobar/#{id}")
17
- FoobarInteractor.find(id)
12
+ Foobar.find(id)
18
13
  end
19
14
 
20
15
  def test_find_each_should_get_correct_path
21
16
  Loquor.expects(:get).with("/foobar?&page=1&per=200").returns([])
22
- FoobarInteractor.find_each
17
+ Foobar.find_each
23
18
  end
24
19
 
25
20
  def test_find_each_should_yield_block
26
21
  Loquor.expects(:get).returns([{id: 1}])
27
22
  ids = []
28
- FoobarInteractor.find_each do |json|
23
+ Foobar.find_each do |json|
29
24
  ids << json['id']
30
25
  end
31
26
  end
@@ -33,7 +28,7 @@ module Loquor
33
28
  def test_where_should_get_correct_path_with_simple_path
34
29
  email = "foobar"
35
30
  Loquor.expects(:get).with("/foobar?email=#{email}").returns([])
36
- FoobarInteractor.where(email: email).to_a
31
+ Foobar.where(email: email).to_a
37
32
  end
38
33
  end
39
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loquor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Walker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-23 00:00:00.000000000 Z
11
+ date: 2013-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: filum
@@ -132,9 +132,10 @@ files:
132
132
  - lib/loquor/http_action.rb
133
133
  - lib/loquor/http_actions/get.rb
134
134
  - lib/loquor/http_actions/post.rb
135
- - lib/loquor/interactor.rb
136
135
  - lib/loquor/interactors.rb
137
- - lib/loquor/representation.rb
136
+ - lib/loquor/object_hash.rb
137
+ - lib/loquor/resource.rb
138
+ - lib/loquor/resource_mock.rb
138
139
  - lib/loquor/version.rb
139
140
  - loquor.gemspec
140
141
  - test/api_calls/index_test.rb
@@ -144,9 +145,8 @@ files:
144
145
  - test/http_action_test.rb
145
146
  - test/http_actions/get_test.rb
146
147
  - test/http_actions/post_test.rb
147
- - test/interactor_test.rb
148
- - test/interactors_test.rb
149
- - test/representation_test.rb
148
+ - test/object_hash_test.rb
149
+ - test/resource_test.rb
150
150
  - test/test_helper.rb
151
151
  homepage: https://www.meducation.net
152
152
  licenses:
@@ -180,8 +180,7 @@ test_files:
180
180
  - test/http_action_test.rb
181
181
  - test/http_actions/get_test.rb
182
182
  - test/http_actions/post_test.rb
183
- - test/interactor_test.rb
184
- - test/interactors_test.rb
185
- - test/representation_test.rb
183
+ - test/object_hash_test.rb
184
+ - test/resource_test.rb
186
185
  - test/test_helper.rb
187
186
  has_rdoc:
@@ -1,29 +0,0 @@
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,22 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- module Loquor
4
- class InteractorTest < Minitest::Test
5
-
6
- {
7
- MediaFile: "/media_files",
8
- User: "/users",
9
- GroupDiscussion: "/group_discussions",
10
- GroupDiscussionPost: "/group_discussion_posts"
11
- }.each do |klass, path|
12
- define_method "test_#{klass}_set_up_correctly" do
13
- assert Loquor.const_defined?(klass)
14
- end
15
-
16
- define_method "test_#{klass}_stores_path_up_correctly" do
17
- assert_equal path, Loquor.const_get(klass).path
18
- end
19
- end
20
- end
21
- end
22
-