prefabc 0.0.8
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 +7 -0
- data/.gitignore +12 -0
- data/.rubocop.yml +24 -0
- data/Gemfile +13 -0
- data/LICENSE +21 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/bin/console.rb +8 -0
- data/circle.yml +7 -0
- data/lib/prefabc.rb +62 -0
- data/lib/prefabc/abstract_resource.rb +75 -0
- data/lib/prefabc/account.rb +12 -0
- data/lib/prefabc/book.rb +17 -0
- data/lib/prefabc/client.rb +23 -0
- data/lib/prefabc/entity.rb +16 -0
- data/lib/prefabc/mixins/creates_subresources.rb +12 -0
- data/lib/prefabc/mixins/lists_subresources.rb +10 -0
- data/lib/prefabc/mixins/reads_subresources.rb +10 -0
- data/lib/prefabc/mixins/updates.rb +10 -0
- data/lib/prefabc/transaction.rb +5 -0
- data/lib/prefabc/version.rb +5 -0
- data/prefabc.gemspec +11 -0
- data/test/integration/book_test.rb +40 -0
- data/test/integration/entity_test.rb +141 -0
- data/test/test_helper.rb +10 -0
- data/test/unit/abstract_resource_test.rb +27 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4a7de0e0ff6fd6a0527742957a1608d682396bf1
|
4
|
+
data.tar.gz: 8f6ff3e9f31bddf8351772985a9f58699d26ec3b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3babe4825ed6f4db21af2d782a7c2558c41727d9ad1ac73275b1e06d061f8e30771054287a4e9567f01738af2aaf12749d45a6dcc27a9bc07be2442746135617
|
7
|
+
data.tar.gz: 9c35c8aa1ca9090920365b8761a885507d32f450ae395c92aff1443d622bfed59ceea681dcad95792541cc15950a72d9603bc5094750dc7008b095a5a120f17b
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# The default values can be found here:
|
2
|
+
# https://github.com/bbatsov/rubocop/blob/master/config/default.yml
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
DisplayCopNames: true
|
6
|
+
|
7
|
+
Documentation:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
# This is a useful metric but it gets triggered by heavy meta-programming. Given
|
11
|
+
# the design decision of thin clients, it seems like heavy meta-programming is
|
12
|
+
# a reasonable choice and therefore this is disabled:
|
13
|
+
Metrics/AbcSize:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Metrics/BlockLength:
|
17
|
+
Exclude:
|
18
|
+
- test/**/*.rb
|
19
|
+
|
20
|
+
Metrics/MethodLength:
|
21
|
+
Max: 20 # The default is 10.
|
22
|
+
|
23
|
+
Style/TrailingCommaInLiteral:
|
24
|
+
EnforcedStyleForMultiline: 'comma'
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require './lib/prefabc'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rubocop/rake_task'
|
4
|
+
|
5
|
+
task default: :test
|
6
|
+
task test: %i[spec rubocop]
|
7
|
+
|
8
|
+
desc 'Run all tests.'
|
9
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
10
|
+
t.pattern = Dir['test/**/*_test.rb']
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'Check style.'
|
14
|
+
RuboCop::RakeTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.8
|
data/bin/console.rb
ADDED
data/circle.yml
ADDED
data/lib/prefabc.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'iniparse'
|
2
|
+
require 'plissken'
|
3
|
+
require 'json'
|
4
|
+
require 'rest-client'
|
5
|
+
|
6
|
+
require "#{File.dirname(__FILE__)}/prefabc/abstract_resource"
|
7
|
+
|
8
|
+
require "#{File.dirname(__FILE__)}/prefabc/mixins/creates_subresources"
|
9
|
+
require "#{File.dirname(__FILE__)}/prefabc/mixins/lists_subresources"
|
10
|
+
require "#{File.dirname(__FILE__)}/prefabc/mixins/reads_subresources"
|
11
|
+
require "#{File.dirname(__FILE__)}/prefabc/mixins/updates"
|
12
|
+
|
13
|
+
require "#{File.dirname(__FILE__)}/prefabc/transaction"
|
14
|
+
require "#{File.dirname(__FILE__)}/prefabc/account"
|
15
|
+
require "#{File.dirname(__FILE__)}/prefabc/book"
|
16
|
+
require "#{File.dirname(__FILE__)}/prefabc/entity"
|
17
|
+
|
18
|
+
require "#{File.dirname(__FILE__)}/prefabc/client"
|
19
|
+
require "#{File.dirname(__FILE__)}/prefabc/version"
|
20
|
+
|
21
|
+
module PrefabC
|
22
|
+
DEFAULT_SCHEME_AND_AUTHORITY = 'https://api.prefabc.com'.freeze
|
23
|
+
@scheme_and_authority ||= DEFAULT_SCHEME_AND_AUTHORITY
|
24
|
+
|
25
|
+
class << self
|
26
|
+
attr_accessor :scheme_and_authority
|
27
|
+
attr_writer :api_key
|
28
|
+
|
29
|
+
def api_key
|
30
|
+
@api_key || raise('No API key given.')
|
31
|
+
end
|
32
|
+
|
33
|
+
def load_config_from_dotfile
|
34
|
+
config_filepath = ENV['HOME'] + '/.prefabc'
|
35
|
+
return unless File.exist?(config_filepath)
|
36
|
+
|
37
|
+
config = IniParse.parse(File.read(config_filepath))
|
38
|
+
default_config = config['default']
|
39
|
+
return unless default_config
|
40
|
+
|
41
|
+
@scheme_and_authority = default_config['scheme_and_authority']
|
42
|
+
@api_key = default_config['api_key']
|
43
|
+
end
|
44
|
+
|
45
|
+
def entities
|
46
|
+
client = Client.new(Entity.new.collection_path)
|
47
|
+
client.get.map { |raw_params| Entity.new(raw_params) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def entity(id)
|
51
|
+
client = Client.new("#{Entity.new.collection_path}/#{id}")
|
52
|
+
Entity.new(client.get)
|
53
|
+
end
|
54
|
+
|
55
|
+
def create_entity(params)
|
56
|
+
client = Client.new(Entity.new.collection_path)
|
57
|
+
Entity.new(client.post(params))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
load_config_from_dotfile
|
62
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module PrefabC
|
2
|
+
class AbstractResource
|
3
|
+
KEYS_TO_PARSE_AS_DATETIME = Set.new(%i[date])
|
4
|
+
IMMUTABLE_PARAMETERS = Set.new(%i[account amount book currency date entity])
|
5
|
+
|
6
|
+
def self.collection_name
|
7
|
+
"#{resource_name}s"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.resource_name
|
11
|
+
name.split('::').last.downcase
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.hierarchy
|
15
|
+
[Entity, Book, Account, Transaction]
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.subresource
|
19
|
+
raise 'This should be implemented in the subclass.'
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.rubify_raw_params(raw_params)
|
23
|
+
tags = raw_params[:tags]
|
24
|
+
params = raw_params.to_snake_keys
|
25
|
+
params[:tags] = tags if tags
|
26
|
+
params
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(raw_params = {})
|
30
|
+
@dirty_params = {}
|
31
|
+
raise 'Argument is expected to be a Hash.' unless raw_params.is_a?(Hash)
|
32
|
+
@params = AbstractResource.rubify_raw_params(raw_params)
|
33
|
+
|
34
|
+
@params.each do |key, value|
|
35
|
+
unless methods.include?(key.to_sym)
|
36
|
+
self.class.class_eval { attr_reader key.to_sym }
|
37
|
+
self.class.send(:define_method, "#{key}=") do |args|
|
38
|
+
resetting_immutable = IMMUTABLE_PARAMETERS.include?(key) &&
|
39
|
+
instance_variable_get("@#{key}")
|
40
|
+
raise "`#{key}` is an immutable property." if resetting_immutable
|
41
|
+
@dirty_params[key] = args
|
42
|
+
instance_variable_set("@#{key}", args)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
if KEYS_TO_PARSE_AS_DATETIME.include?(key)
|
46
|
+
instance_variable_set("@#{key}", Time.parse(value))
|
47
|
+
else
|
48
|
+
instance_variable_set("@#{key}", value)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def subresource_collection_path
|
54
|
+
"#{resource_path}/#{self.class.subresource.collection_name}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def resource_path
|
58
|
+
"#{collection_path}/#{id}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def collection_path
|
62
|
+
"#{parent_path}/#{self.class.collection_name}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def parent_path
|
66
|
+
@parent_path ||= begin
|
67
|
+
hierarchy = self.class.hierarchy
|
68
|
+
parents = hierarchy[0...hierarchy.index(self.class)]
|
69
|
+
parents.inject('') do |partial, klass|
|
70
|
+
"#{partial}/#{klass.collection_name}/#{send(klass.resource_name)}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/prefabc/book.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module PrefabC
|
2
|
+
class Book < AbstractResource
|
3
|
+
def self.subresource
|
4
|
+
Account
|
5
|
+
end
|
6
|
+
|
7
|
+
include ListsSubresources
|
8
|
+
include ReadsSubresources
|
9
|
+
include CreatesSubresources
|
10
|
+
include Updates
|
11
|
+
|
12
|
+
def post_transaction_set(transaction_set)
|
13
|
+
client = Client.new("/entities/#{entity}/books/#{id}/transactions")
|
14
|
+
client.post(transaction_set)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PrefabC
|
2
|
+
class Client
|
3
|
+
def initialize(path)
|
4
|
+
url = "#{PrefabC.scheme_and_authority}#{path}"
|
5
|
+
@resource = RestClient::Resource.new(url, '', PrefabC.api_key)
|
6
|
+
end
|
7
|
+
|
8
|
+
def get
|
9
|
+
response = @resource.get
|
10
|
+
JSON.parse(response.body, symbolize_names: true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def patch(params = {})
|
14
|
+
response = @resource.patch(params)
|
15
|
+
JSON.parse(response.body, symbolize_names: true)
|
16
|
+
end
|
17
|
+
|
18
|
+
def post(params = {})
|
19
|
+
response = @resource.post(params)
|
20
|
+
JSON.parse(response.body, symbolize_names: true)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module PrefabC
|
2
|
+
class Entity < AbstractResource
|
3
|
+
def self.subresource
|
4
|
+
Book
|
5
|
+
end
|
6
|
+
|
7
|
+
include ListsSubresources
|
8
|
+
include ReadsSubresources
|
9
|
+
include CreatesSubresources
|
10
|
+
include Updates
|
11
|
+
|
12
|
+
def self.collection_name
|
13
|
+
'entities'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module PrefabC
|
2
|
+
module CreatesSubresources
|
3
|
+
def self.included(base)
|
4
|
+
base.send(
|
5
|
+
:define_method, "create_#{base.subresource.resource_name}"
|
6
|
+
) do |params|
|
7
|
+
client = Client.new(subresource_collection_path)
|
8
|
+
base.subresource.new(client.post(params))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module PrefabC
|
2
|
+
module ListsSubresources
|
3
|
+
def self.included(base)
|
4
|
+
base.send(:define_method, base.subresource.collection_name) do
|
5
|
+
client = Client.new(subresource_collection_path)
|
6
|
+
client.get.map { |raw_params| base.subresource.new(raw_params) }
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/prefabc.gemspec
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.name = 'prefabc'
|
3
|
+
gem.version = File.read(File.expand_path('../VERSION', __FILE__))
|
4
|
+
gem.author = 'Prefab C'
|
5
|
+
gem.summary = 'Ruby bindings for Prefab C.'
|
6
|
+
gem.files = `git ls-files`.split("\n")
|
7
|
+
|
8
|
+
gem.add_dependency 'iniparse'
|
9
|
+
gem.add_dependency 'plissken'
|
10
|
+
gem.add_dependency 'rest-client'
|
11
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../test_helper"
|
2
|
+
|
3
|
+
describe 'Book' do
|
4
|
+
before do
|
5
|
+
PrefabC.scheme_and_authority = 'https://api.prefabc.com'
|
6
|
+
PrefabC.api_key = 'api_key'
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'can post a transaction set' do
|
10
|
+
transaction_set = {
|
11
|
+
date: Time.now,
|
12
|
+
transactions: [
|
13
|
+
{ account: 'bank_account', amount: 150 },
|
14
|
+
{ account: 'profit_and_loss', amount: -150 },
|
15
|
+
],
|
16
|
+
}
|
17
|
+
book = Book.new(currency: :USD, entity: 'entity_id', id: 'book_id')
|
18
|
+
api_response_body = {
|
19
|
+
id: 'book_id',
|
20
|
+
entity: 'entity_id',
|
21
|
+
currency: :USD,
|
22
|
+
}.to_json
|
23
|
+
api_response = instance_double(
|
24
|
+
RestClient::Response, body: api_response_body
|
25
|
+
)
|
26
|
+
client = instance_double(RestClient::Resource, post: api_response)
|
27
|
+
expect(RestClient::Resource).to receive(:new)
|
28
|
+
.with(
|
29
|
+
"https://api.prefabc.com/entities/#{book.entity}/books/#{book.id}/" \
|
30
|
+
'transactions', '', 'api_key'
|
31
|
+
)
|
32
|
+
.and_return(client)
|
33
|
+
book.post_transaction_set(transaction_set)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'errors if an immutable parameter update attempt occurs' do
|
37
|
+
book = Book.new(id: 'entity_id', currency: :CAD)
|
38
|
+
expect { book.currency = :USD }.to raise_error(StandardError)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../test_helper"
|
2
|
+
|
3
|
+
describe 'Entity' do
|
4
|
+
before do
|
5
|
+
PrefabC.scheme_and_authority = 'https://api.prefabc.com'
|
6
|
+
PrefabC.api_key = 'api_key'
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'can request and parse a listing of all entities' do
|
10
|
+
successful_api_response_body = [{
|
11
|
+
id: 'id',
|
12
|
+
group: 'group',
|
13
|
+
name: 'name',
|
14
|
+
default: true,
|
15
|
+
}].to_json
|
16
|
+
successful_api_response = instance_double(
|
17
|
+
RestClient::Response, body: successful_api_response_body
|
18
|
+
)
|
19
|
+
client = instance_double(RestClient::Resource, get: successful_api_response)
|
20
|
+
expect(RestClient::Resource).to receive(:new)
|
21
|
+
.with('https://api.prefabc.com/entities', '', 'api_key')
|
22
|
+
.and_return(client)
|
23
|
+
entity_list = PrefabC.entities
|
24
|
+
expect(entity_list.first.id).to eq('id')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'can request and parse a specific entity' do
|
28
|
+
successful_api_response_body = {
|
29
|
+
id: 'id',
|
30
|
+
group: 'group',
|
31
|
+
name: 'name',
|
32
|
+
default: true,
|
33
|
+
}.to_json
|
34
|
+
successful_api_response = instance_double(
|
35
|
+
RestClient::Response, body: successful_api_response_body
|
36
|
+
)
|
37
|
+
client = instance_double(RestClient::Resource, get: successful_api_response)
|
38
|
+
expect(RestClient::Resource).to receive(:new)
|
39
|
+
.with('https://api.prefabc.com/entities/id', '', 'api_key')
|
40
|
+
.and_return(client)
|
41
|
+
entity = PrefabC.entity('id')
|
42
|
+
expect(entity.name).to eq('name')
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'can create an entity' do
|
46
|
+
successful_api_response_body = {
|
47
|
+
id: 'id',
|
48
|
+
group: 'group',
|
49
|
+
name: 'name',
|
50
|
+
default: true,
|
51
|
+
}.to_json
|
52
|
+
successful_api_response = instance_double(
|
53
|
+
RestClient::Response, body: successful_api_response_body
|
54
|
+
)
|
55
|
+
expect_any_instance_of(RestClient::Resource).to receive(:post)
|
56
|
+
.with({})
|
57
|
+
.and_return(successful_api_response)
|
58
|
+
entity = PrefabC.create_entity({})
|
59
|
+
expect(entity.id).to eq('id')
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'can list books' do
|
63
|
+
entity = Entity.new(id: 'entity_id')
|
64
|
+
successful_api_response_body = [{
|
65
|
+
id: 'book_id',
|
66
|
+
currency: :USD,
|
67
|
+
entity: entity.id,
|
68
|
+
default: true,
|
69
|
+
}].to_json
|
70
|
+
successful_api_response = instance_double(
|
71
|
+
RestClient::Response, body: successful_api_response_body
|
72
|
+
)
|
73
|
+
client = instance_double(RestClient::Resource, get: successful_api_response)
|
74
|
+
expect(RestClient::Resource).to receive(:new)
|
75
|
+
.with('https://api.prefabc.com/entities/entity_id/books', '', 'api_key')
|
76
|
+
.and_return(client)
|
77
|
+
books = entity.books
|
78
|
+
expect(books.first.id).to eq('book_id')
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'can get a specific book' do
|
82
|
+
book_id = 'book_id'
|
83
|
+
entity = Entity.new(id: 'entity_id')
|
84
|
+
successful_api_response_body = {
|
85
|
+
id: book_id,
|
86
|
+
currency: :USD,
|
87
|
+
entity: entity.id,
|
88
|
+
default: true,
|
89
|
+
}.to_json
|
90
|
+
successful_api_response = instance_double(
|
91
|
+
RestClient::Response, body: successful_api_response_body
|
92
|
+
)
|
93
|
+
client = instance_double(RestClient::Resource, get: successful_api_response)
|
94
|
+
expect(RestClient::Resource).to receive(:new)
|
95
|
+
.with(
|
96
|
+
"https://api.prefabc.com/entities/entity_id/books/#{book_id}",
|
97
|
+
'', 'api_key'
|
98
|
+
)
|
99
|
+
.and_return(client)
|
100
|
+
book = entity.book(book_id)
|
101
|
+
expect(book.id).to eq(book_id)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'can create a book' do
|
105
|
+
book_id = 'book_id'
|
106
|
+
entity = Entity.new(id: 'entity_id')
|
107
|
+
successful_api_response_body = {
|
108
|
+
id: book_id,
|
109
|
+
currency: :USD,
|
110
|
+
entity: entity.id,
|
111
|
+
default: true,
|
112
|
+
}.to_json
|
113
|
+
successful_api_response = instance_double(
|
114
|
+
RestClient::Response, body: successful_api_response_body
|
115
|
+
)
|
116
|
+
expect_any_instance_of(RestClient::Resource).to receive(:post)
|
117
|
+
.with(currency: :USD, entity: entity.id)
|
118
|
+
.and_return(successful_api_response)
|
119
|
+
book = entity.create_book(currency: :USD, entity: entity.id)
|
120
|
+
expect(book.id).to eq(book_id)
|
121
|
+
expect(book.collection_path).to eq("/entities/#{entity.id}/books")
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'can be updated' do
|
125
|
+
entity = Entity.new(id: 'entity_id', name: 'original_name')
|
126
|
+
entity.name = 'updated_name'
|
127
|
+
successful_api_response_body = {
|
128
|
+
id: 'entity_id',
|
129
|
+
group: 'group_id',
|
130
|
+
default: true,
|
131
|
+
name: 'updated_name',
|
132
|
+
}.to_json
|
133
|
+
successful_api_response = instance_double(
|
134
|
+
RestClient::Response, body: successful_api_response_body
|
135
|
+
)
|
136
|
+
expect_any_instance_of(RestClient::Resource).to receive(:patch)
|
137
|
+
.with(name: 'updated_name')
|
138
|
+
.and_return(successful_api_response)
|
139
|
+
entity.update!
|
140
|
+
end
|
141
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../test_helper"
|
2
|
+
|
3
|
+
describe 'AbstractResource' do
|
4
|
+
before do
|
5
|
+
class DummyResource < AbstractResource
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'parses a returned JSON object as expected' do
|
10
|
+
datetime = Time.new(2017, 5, 4)
|
11
|
+
balance_sheet_rollup_tag = :'balance-sheet-rollup'
|
12
|
+
hash_to_parse = {
|
13
|
+
className: 'dummy',
|
14
|
+
account: 'profit_and_loss',
|
15
|
+
amount: 314,
|
16
|
+
currency: 'USD',
|
17
|
+
date: datetime.to_s,
|
18
|
+
tags: { balance_sheet_rollup_tag => 'assets' },
|
19
|
+
}
|
20
|
+
dummy = DummyResource.new(hash_to_parse)
|
21
|
+
expect(dummy.class_name).to eq('dummy')
|
22
|
+
expect(dummy.account).to eq('profit_and_loss')
|
23
|
+
expect(dummy.amount).to eq(314)
|
24
|
+
expect(dummy.date).to eq(datetime)
|
25
|
+
expect(dummy.tags[balance_sheet_rollup_tag]).to eq('assets')
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prefabc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.8
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Prefab C
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: iniparse
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: plissken
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rest-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- ".gitignore"
|
62
|
+
- ".rubocop.yml"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- Rakefile
|
66
|
+
- VERSION
|
67
|
+
- bin/console.rb
|
68
|
+
- circle.yml
|
69
|
+
- lib/prefabc.rb
|
70
|
+
- lib/prefabc/abstract_resource.rb
|
71
|
+
- lib/prefabc/account.rb
|
72
|
+
- lib/prefabc/book.rb
|
73
|
+
- lib/prefabc/client.rb
|
74
|
+
- lib/prefabc/entity.rb
|
75
|
+
- lib/prefabc/mixins/creates_subresources.rb
|
76
|
+
- lib/prefabc/mixins/lists_subresources.rb
|
77
|
+
- lib/prefabc/mixins/reads_subresources.rb
|
78
|
+
- lib/prefabc/mixins/updates.rb
|
79
|
+
- lib/prefabc/transaction.rb
|
80
|
+
- lib/prefabc/version.rb
|
81
|
+
- prefabc.gemspec
|
82
|
+
- test/integration/book_test.rb
|
83
|
+
- test/integration/entity_test.rb
|
84
|
+
- test/test_helper.rb
|
85
|
+
- test/unit/abstract_resource_test.rb
|
86
|
+
homepage:
|
87
|
+
licenses: []
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.6.12
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Ruby bindings for Prefab C.
|
109
|
+
test_files: []
|