pennylane 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -1
- data/Gemfile.lock +1 -1
- data/README.md +14 -1
- data/lib/pennylane/list_object.rb +1 -1
- data/lib/pennylane/object_types.rb +15 -0
- data/lib/pennylane/resources/base.rb +1 -1
- data/lib/pennylane/util.rb +1 -2
- data/lib/pennylane/version.rb +1 -1
- data/lib/pennylane.rb +2 -11
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2e821259dc8683a82dd041e681f09c8eee4982f0a945c830709a7dca9409e72
|
4
|
+
data.tar.gz: f7a0db763e780102951c050aaca06bcb8c178dbc3524defdaf4cd3389f982733
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f2f0dd8084a8017e40e463f70c9664e0cf684f9e656da437edcb48f30c429a827f38412ff93d61675faf31e56063d88d1ad8bac688a392789d586defd6833b5
|
7
|
+
data.tar.gz: e3745c63a10ddb89fff5d114bdff477fcd20ac3341ae7c9f44f27175db5a40f823befdcb3c6658aa336b9f71914ff93c17ba3b74f95934208750c32f49f2dc89
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -16,9 +16,22 @@ Install the gem and add to the application's Gemfile by executing:
|
|
16
16
|
$ bundle add pennylane
|
17
17
|
|
18
18
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
19
|
+
```ruby
|
20
|
+
# Add to gemfile
|
21
|
+
gem 'pennylane'
|
22
|
+
```
|
19
23
|
|
20
|
-
|
24
|
+
For Rails app :
|
25
|
+
```ruby
|
26
|
+
# Create initializers/pennylane.rb
|
27
|
+
Pennylane.api_key = Rails.application.credentials.dig(:pennylane, :api_key)
|
21
28
|
|
29
|
+
# Add credentials to config/credentials.yml.enc
|
30
|
+
$ EDITOR=vim bin/rails credentials:edit
|
31
|
+
|
32
|
+
pennylane:
|
33
|
+
api_key: 'x0fd....'
|
34
|
+
```
|
22
35
|
## Requirements
|
23
36
|
Ruby 2.3+.
|
24
37
|
|
@@ -19,7 +19,7 @@ module Pennylane
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def key_for(resp)
|
22
|
-
resp.keys.find { |k| Pennylane::
|
22
|
+
resp.keys.find { |k| Pennylane::ObjectTypes.object_names_to_classes.keys.include?(Util.singularize(k.to_s)) } || resp.keys.find { |k| resp[k].is_a? Array }
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Pennylane
|
2
|
+
module ObjectTypes
|
3
|
+
def self.object_names_to_classes
|
4
|
+
{
|
5
|
+
ListObject.object_name => ListObject,
|
6
|
+
Category.object_name => Category,
|
7
|
+
CategoryGroup.object_name => CategoryGroup,
|
8
|
+
Customer.object_name => Customer,
|
9
|
+
CustomerInvoice.object_name => CustomerInvoice,
|
10
|
+
Product.object_name => Product,
|
11
|
+
Supplier.object_name => Supplier
|
12
|
+
}.freeze
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -74,7 +74,7 @@ module Pennylane
|
|
74
74
|
# So we can call directly method on the object rather than going through his key
|
75
75
|
# Pennylane::Customer.retrieve('any-id').name == Pennylane::Customer.retrieve('any-id').customer.name
|
76
76
|
def method_missing(method_name, *args, &block)
|
77
|
-
raise NoMethodError, "undefined method `#{method_name}` for #{self.class}" unless object
|
77
|
+
raise NoMethodError, "undefined method `#{method_name}` for #{self.class}.\nMethods available : #{@values.keys}" unless object
|
78
78
|
object.send(method_name, *args, &block)
|
79
79
|
end
|
80
80
|
|
data/lib/pennylane/util.rb
CHANGED
@@ -32,7 +32,6 @@ module Pennylane
|
|
32
32
|
# Since we don't have the ability to change the API response.
|
33
33
|
# We can achieve this by calling normalize_response(response, with: {invoice: 'customer_invoice'})
|
34
34
|
def normalize_response(object, with={})
|
35
|
-
# puts object.inspect
|
36
35
|
case object
|
37
36
|
when Hash
|
38
37
|
new_hash = {}
|
@@ -85,7 +84,7 @@ module Pennylane
|
|
85
84
|
end
|
86
85
|
|
87
86
|
def klass_for(object)
|
88
|
-
Pennylane::
|
87
|
+
Pennylane::ObjectTypes.object_names_to_classes[singularize(object)] || Pennylane::Object
|
89
88
|
rescue
|
90
89
|
Pennylane::Object
|
91
90
|
end
|
data/lib/pennylane/version.rb
CHANGED
data/lib/pennylane.rb
CHANGED
@@ -11,8 +11,9 @@ require 'forwardable'
|
|
11
11
|
require 'uri'
|
12
12
|
require 'net/http'
|
13
13
|
|
14
|
-
Dir[
|
14
|
+
Dir[File.join(__dir__, 'pennylane/resources/*.rb')].each {|file| require file }
|
15
15
|
|
16
|
+
require 'pennylane/object_types'
|
16
17
|
|
17
18
|
module Pennylane
|
18
19
|
class Error < StandardError; end
|
@@ -20,16 +21,6 @@ module Pennylane
|
|
20
21
|
class ConfigurationError < Error; end
|
21
22
|
class NotFoundError < Error; end
|
22
23
|
|
23
|
-
API_RESOURCES = {
|
24
|
-
ListObject.object_name => ListObject,
|
25
|
-
Category.object_name => Category,
|
26
|
-
CategoryGroup.object_name => CategoryGroup,
|
27
|
-
Customer.object_name => Customer,
|
28
|
-
CustomerInvoice.object_name => CustomerInvoice,
|
29
|
-
Product.object_name => Product,
|
30
|
-
Supplier.object_name => Supplier
|
31
|
-
}.freeze
|
32
|
-
|
33
24
|
@config = Pennylane::Configuration.new
|
34
25
|
# So we can have a module Pennylane that can be a class as well Pennylane.api_key = '1234'
|
35
26
|
class << self
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pennylane
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephane Bounmy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: vcr
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- lib/pennylane/configuration.rb
|
88
88
|
- lib/pennylane/list_object.rb
|
89
89
|
- lib/pennylane/object.rb
|
90
|
+
- lib/pennylane/object_types.rb
|
90
91
|
- lib/pennylane/resources/base.rb
|
91
92
|
- lib/pennylane/resources/category.rb
|
92
93
|
- lib/pennylane/resources/category_group.rb
|