jurnal_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.template +2 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +100 -0
- data/LICENSE +674 -0
- data/README.md +32 -0
- data/Rakefile +6 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/jurnal-api.gemspec +44 -0
- data/lib/faraday/raise_http_exception.rb +47 -0
- data/lib/jurnal_api.rb +26 -0
- data/lib/jurnal_api/api.rb +34 -0
- data/lib/jurnal_api/client.rb +15 -0
- data/lib/jurnal_api/client/customers.rb +33 -0
- data/lib/jurnal_api/client/journal_entries.rb +33 -0
- data/lib/jurnal_api/client/products.rb +17 -0
- data/lib/jurnal_api/client/receive_payments.rb +33 -0
- data/lib/jurnal_api/client/recurring_schedules.rb +12 -0
- data/lib/jurnal_api/client/sales_invoices.rb +33 -0
- data/lib/jurnal_api/client/sales_order_payments.rb +27 -0
- data/lib/jurnal_api/client/sales_orders.rb +36 -0
- data/lib/jurnal_api/configuration.rb +92 -0
- data/lib/jurnal_api/connection.rb +43 -0
- data/lib/jurnal_api/error.rb +46 -0
- data/lib/jurnal_api/request.rb +54 -0
- data/lib/jurnal_api/response.rb +25 -0
- data/lib/jurnal_api/version.rb +3 -0
- metadata +254 -0
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# JurnalApi
|
2
|
+
|
3
|
+
A Ruby wrapper for the Jurnal REST APIs
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'jurnal_api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install jurnal_api
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
```
|
23
|
+
$ bundle exec irb -I lib
|
24
|
+
|
25
|
+
require 'jurnal_api'
|
26
|
+
client = JurnalApi::Client.new(access_token: ENV['JURNAL_COMPANY_API_KEY'], base_url: ENV['JURNAL_API_BASE_URL'])
|
27
|
+
client.products
|
28
|
+
```
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mekari/ruby-jurnal-client.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "jurnal/api"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/jurnal-api.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require File.expand_path('../lib/jurnal_api/version', __FILE__)
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "jurnal_api"
|
9
|
+
spec.version = JurnalApi::VERSION
|
10
|
+
spec.authors = ["mekari-devs"]
|
11
|
+
spec.email = ["developer@mekari.com"]
|
12
|
+
|
13
|
+
spec.summary = %q{Ruby wrapper for the Jurnal API.}
|
14
|
+
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
15
|
+
spec.homepage = "https://github.com/mekari-engineering/jurnal_api"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
30
|
+
spec.add_development_dependency "byebug", "11.1.3"
|
31
|
+
spec.add_development_dependency "capybara", "2.5.0"
|
32
|
+
spec.add_development_dependency "pry"
|
33
|
+
spec.add_development_dependency "rack", "2.2.3"
|
34
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
spec.add_development_dependency "shoulda-context", "1.2.2"
|
37
|
+
spec.add_development_dependency "shoulda-matchers", "3.1.1"
|
38
|
+
spec.add_development_dependency "webmock", "3.8.3"
|
39
|
+
|
40
|
+
# dependency
|
41
|
+
spec.add_dependency "faraday", "0.15.4"
|
42
|
+
spec.add_dependency "faraday_middleware", "0.13.1"
|
43
|
+
spec.add_dependency "dotenv", "2.7.5"
|
44
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# @private
|
4
|
+
module FaradayMiddleware
|
5
|
+
# @private
|
6
|
+
class RaiseHttpException < Faraday::Middleware
|
7
|
+
def call(env)
|
8
|
+
@app.call(env).on_complete do |response|
|
9
|
+
case response[:status].to_i
|
10
|
+
when 400
|
11
|
+
raise JurnalApi::BadRequest, error_message_400(response)
|
12
|
+
when 404
|
13
|
+
raise JurnalApi::NotFound, error_message_400(response)
|
14
|
+
when 409
|
15
|
+
raise JurnalApi::Conflict.new error_message_400(response), response[:body]
|
16
|
+
when 422
|
17
|
+
raise JurnalApi::UnprocessableEntity.new error_message_400(response), response[:body]
|
18
|
+
when 429
|
19
|
+
raise JurnalApi::TooManyRequests, error_message_400(response)
|
20
|
+
when 500
|
21
|
+
raise JurnalApi::InternalServerError, error_message_500(response, "Something is went wrong.")
|
22
|
+
when 502
|
23
|
+
raise JurnalApi::BadGateway, error_message_500(response, "Bad gateway.")
|
24
|
+
when 503
|
25
|
+
raise JurnalApi::ServiceUnavailable, error_message_500(response, "Jurnal is rate limiting your requests.")
|
26
|
+
when 504
|
27
|
+
raise JurnalApi::GatewayTimeout, error_message_500(response, "504 Gateway Time-out")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize(app)
|
33
|
+
super app
|
34
|
+
@parser = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def error_message_400(response)
|
40
|
+
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def error_message_500(response, body=nil)
|
44
|
+
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{[response[:status].to_s + ':', body].compact.join(' ')}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/jurnal_api.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../jurnal_api/error', __FILE__)
|
2
|
+
require File.expand_path('../jurnal_api/configuration', __FILE__)
|
3
|
+
require File.expand_path('../jurnal_api/api', __FILE__)
|
4
|
+
require File.expand_path('../jurnal_api/client', __FILE__)
|
5
|
+
require File.expand_path('../jurnal_api/response', __FILE__)
|
6
|
+
|
7
|
+
require 'dotenv/load'
|
8
|
+
|
9
|
+
module JurnalApi
|
10
|
+
extend Configuration
|
11
|
+
|
12
|
+
def self.client(options={})
|
13
|
+
JurnalApi::Client.new(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Delegate to JurnalApi::Client
|
17
|
+
def self.method_missing(method, *args, &block)
|
18
|
+
return super unless client.respond_to?(method)
|
19
|
+
client.send(method, *args, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Delegate to JurnalApi::Client
|
23
|
+
def self.respond_to?(method, include_all=false)
|
24
|
+
return client.respond_to?(method, include_all) || super
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path('../connection', __FILE__)
|
2
|
+
require File.expand_path('../request', __FILE__)
|
3
|
+
|
4
|
+
module JurnalApi
|
5
|
+
# @private
|
6
|
+
class API
|
7
|
+
# @private
|
8
|
+
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
9
|
+
attr_reader :endpoint
|
10
|
+
|
11
|
+
# Creates a new API
|
12
|
+
def initialize(options={})
|
13
|
+
options = JurnalApi.options.merge(options)
|
14
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
15
|
+
send("#{key}=", options[key])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def config
|
20
|
+
conf = {}
|
21
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
22
|
+
conf[key] = send key
|
23
|
+
end
|
24
|
+
conf
|
25
|
+
end
|
26
|
+
|
27
|
+
def endpoint
|
28
|
+
base_url + '/' + authorization_path + '/' + api_version
|
29
|
+
end
|
30
|
+
|
31
|
+
include Connection
|
32
|
+
include Request
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module JurnalApi
|
2
|
+
# Wrapper for the JurnalApi REST API
|
3
|
+
class Client < API
|
4
|
+
Dir[File.expand_path('../client/*.rb', __FILE__)].each{|f| require f}
|
5
|
+
|
6
|
+
include JurnalApi::Client::Customers
|
7
|
+
include JurnalApi::Client::JournalEntries
|
8
|
+
include JurnalApi::Client::Products
|
9
|
+
include JurnalApi::Client::RecurringSchedules
|
10
|
+
include JurnalApi::Client::ReceivePayment
|
11
|
+
include JurnalApi::Client::SalesOrderPayments
|
12
|
+
include JurnalApi::Client::SalesOrders
|
13
|
+
include JurnalApi::Client::SalesInvoices
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module JurnalApi
|
2
|
+
class Client
|
3
|
+
# Defines methods related to SalesOrders
|
4
|
+
module Customers
|
5
|
+
|
6
|
+
def customers(params = {})
|
7
|
+
response = get('customers', params)
|
8
|
+
response
|
9
|
+
end
|
10
|
+
|
11
|
+
def customer_find(id)
|
12
|
+
response = get("customers/#{id}")
|
13
|
+
response
|
14
|
+
end
|
15
|
+
|
16
|
+
def customer_create(params = {})
|
17
|
+
response = post('customers', params)
|
18
|
+
response
|
19
|
+
end
|
20
|
+
|
21
|
+
def customer_update(id, params = {})
|
22
|
+
response = put("customers/#{id}", params)
|
23
|
+
response
|
24
|
+
end
|
25
|
+
|
26
|
+
def customer_delete(id)
|
27
|
+
response = delete("customers/#{id}")
|
28
|
+
response
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module JurnalApi
|
2
|
+
class Client
|
3
|
+
# Defines methods related to SalesOrders
|
4
|
+
module JournalEntries
|
5
|
+
|
6
|
+
def journal_entries(params = {})
|
7
|
+
response = get('journal_entries', params)
|
8
|
+
response
|
9
|
+
end
|
10
|
+
|
11
|
+
def journal_entry_find(id)
|
12
|
+
response = get("journal_entries/#{id}")
|
13
|
+
response
|
14
|
+
end
|
15
|
+
|
16
|
+
def journal_entry_create(params = {})
|
17
|
+
response = post('journal_entries', params)
|
18
|
+
response
|
19
|
+
end
|
20
|
+
|
21
|
+
def journal_entry_update(id, params = {})
|
22
|
+
response = put("journal_entries/#{id}", params)
|
23
|
+
response
|
24
|
+
end
|
25
|
+
|
26
|
+
def journal_entry_delete(id)
|
27
|
+
response = delete("journal_entries/#{id}")
|
28
|
+
response
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module JurnalApi
|
2
|
+
class Client
|
3
|
+
# Defines methods related to Products
|
4
|
+
module Products
|
5
|
+
|
6
|
+
def products(params = {})
|
7
|
+
response = get('products', params)
|
8
|
+
response
|
9
|
+
end
|
10
|
+
|
11
|
+
def product_find(id)
|
12
|
+
response = get("products/#{id}")
|
13
|
+
response
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module JurnalApi
|
2
|
+
class Client
|
3
|
+
# Defines methods related to ReceivePayment
|
4
|
+
module ReceivePayment
|
5
|
+
|
6
|
+
def receive_payments(params = {})
|
7
|
+
response = get('receive_payments', params)
|
8
|
+
response
|
9
|
+
end
|
10
|
+
|
11
|
+
def receive_payment_find(id)
|
12
|
+
response = get("receive_payments/#{id}")
|
13
|
+
response
|
14
|
+
end
|
15
|
+
|
16
|
+
def receive_payment_create(params = {})
|
17
|
+
response = post('receive_payments', params)
|
18
|
+
response
|
19
|
+
end
|
20
|
+
|
21
|
+
def receive_payment_update(id, params = {})
|
22
|
+
response = put("receive_payments/#{id}", params)
|
23
|
+
response
|
24
|
+
end
|
25
|
+
|
26
|
+
def receive_payment_delete(id)
|
27
|
+
response = delete("receive_payments/#{id}")
|
28
|
+
response
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module JurnalApi
|
2
|
+
class Client
|
3
|
+
# Defines methods related to SalesOrders
|
4
|
+
module SalesInvoices
|
5
|
+
|
6
|
+
def sales_invoices(params = {})
|
7
|
+
response = get('sales_invoices', params)
|
8
|
+
response
|
9
|
+
end
|
10
|
+
|
11
|
+
def sales_invoice_find(id)
|
12
|
+
response = get("sales_invoices/#{id}")
|
13
|
+
response
|
14
|
+
end
|
15
|
+
|
16
|
+
def sales_invoice_create(params = {})
|
17
|
+
response = post('sales_invoices', params)
|
18
|
+
response
|
19
|
+
end
|
20
|
+
|
21
|
+
def sales_invoice_update(id, params = {})
|
22
|
+
response = put("sales_invoices/#{id}", params)
|
23
|
+
response
|
24
|
+
end
|
25
|
+
|
26
|
+
def sales_invoice_delete(id)
|
27
|
+
response = delete("sales_invoices/#{id}")
|
28
|
+
response
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module JurnalApi
|
2
|
+
class Client
|
3
|
+
# Defines methods related to SalesOrderPayments
|
4
|
+
module SalesOrderPayments
|
5
|
+
|
6
|
+
def sales_order_payments(params = {})
|
7
|
+
response = get('sales_order_payments', params)
|
8
|
+
response
|
9
|
+
end
|
10
|
+
|
11
|
+
def sales_order_payments_find(id)
|
12
|
+
response = get("sales_order_payments/#{id}")
|
13
|
+
response
|
14
|
+
end
|
15
|
+
|
16
|
+
def sales_order_payment_create(params = {})
|
17
|
+
response = post('sales_order_payments', params)
|
18
|
+
response
|
19
|
+
end
|
20
|
+
|
21
|
+
def sales_order_payment_delete(id)
|
22
|
+
response = delete("sales_order_payments/#{id}")
|
23
|
+
response
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module JurnalApi
|
2
|
+
class Client
|
3
|
+
# Defines methods related to SalesOrders
|
4
|
+
module SalesOrders
|
5
|
+
|
6
|
+
def sales_orders(params = {})
|
7
|
+
response = get('sales_orders', params)
|
8
|
+
response
|
9
|
+
end
|
10
|
+
|
11
|
+
def sales_order_find(id)
|
12
|
+
response = get("sales_orders/#{id}")
|
13
|
+
response
|
14
|
+
end
|
15
|
+
|
16
|
+
def sales_order_create(params = {})
|
17
|
+
response = post('sales_orders', params)
|
18
|
+
response
|
19
|
+
end
|
20
|
+
|
21
|
+
def sales_order_convert_to_invoice(id, params = {})
|
22
|
+
url = "sales_orders/#{id}/convert_to_invoice"
|
23
|
+
response = post(url, params)
|
24
|
+
|
25
|
+
response
|
26
|
+
end
|
27
|
+
|
28
|
+
def sales_order_close(id)
|
29
|
+
url = "sales_orders/#{id}/close_order"
|
30
|
+
response = post(url)
|
31
|
+
|
32
|
+
response
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|