parasut_ruby_sdk 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/.gitignore +11 -0
- data/Gemfile +4 -0
- data/README.md +46 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/conf/cacert.pem +0 -0
- data/examples/examples.rb +29 -0
- data/lib/parasut_ruby_sdk/hash.rb +5 -0
- data/lib/parasut_ruby_sdk/helpers/data_helper.rb +45 -0
- data/lib/parasut_ruby_sdk/rest/account.rb +24 -0
- data/lib/parasut_ruby_sdk/rest/base_request.rb +154 -0
- data/lib/parasut_ruby_sdk/rest/category.rb +28 -0
- data/lib/parasut_ruby_sdk/rest/contact.rb +40 -0
- data/lib/parasut_ruby_sdk/rest/errors.rb +24 -0
- data/lib/parasut_ruby_sdk/rest/parasut.rb +32 -0
- data/lib/parasut_ruby_sdk/rest/product.rb +32 -0
- data/lib/parasut_ruby_sdk/rest/sales_invoice.rb +56 -0
- data/lib/parasut_ruby_sdk/util/configuration.rb +39 -0
- data/lib/parasut_ruby_sdk/util/request_type.rb +67 -0
- data/lib/parasut_ruby_sdk/version.rb +3 -0
- data/lib/parasut_ruby_sdk.rb +22 -0
- data/parasut_ruby_sdk.gemspec +23 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2da2dbb4ee633a776209f0fa35a0286f645c9d2f
|
4
|
+
data.tar.gz: 3f27dae6d09d664d91976d7831223fa44527e039
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 831d5849c79c171266bca168ddf54af3fa9d7d0c6bdd1fa86abdb47d1d723464be619cdd0c1244115e2b85992d986db2cf0062ebacb96290cb9113d192a600fd
|
7
|
+
data.tar.gz: c6d79e0716ce623e732d88f0f10efbd94430c439f067cbe55e174aab92dc6c00aa90a708a6c9f8b953711916ac40339b17365fc8f9bddc8dbc09878b9911951d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Parasut Ruby Sdk
|
2
|
+
|
3
|
+
* [API Documentation](https://api.parasut.com/docs)
|
4
|
+
* [Examples](https://github.com/lab2023/parasut-ruby-sdk/tree/develop/examples)
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'parasut_ruby_sdk'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install parasut_ruby_sdk
|
21
|
+
|
22
|
+
## Development
|
23
|
+
|
24
|
+
$ bundle exec ruby examples/examples.rb
|
25
|
+
|
26
|
+
# Contributing
|
27
|
+
|
28
|
+
Once you've made your great commits:
|
29
|
+
|
30
|
+
1. Fork Project
|
31
|
+
2. Create a topic branch - git checkout -b my_branch
|
32
|
+
3. Push to your branch - git push origin my_branch
|
33
|
+
4. Create a Pull Request from your branch
|
34
|
+
5. That's it!
|
35
|
+
|
36
|
+
# Credits
|
37
|
+
|
38
|
+
![lab2023](http://lab2023.com/assets/images/named-logo.png)
|
39
|
+
|
40
|
+
- Builder is maintained and funded by [lab2023 - information technologies](http://lab2023.com/)
|
41
|
+
- Thank you to all the [contributors!](../../graphs/contributors)
|
42
|
+
- The names and logos for lab2023 are trademarks of lab2023, inc.
|
43
|
+
|
44
|
+
# License
|
45
|
+
|
46
|
+
Copyright 2016 lab2023 – information technologies
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'parasut_ruby_sdk'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require 'pry'
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/conf/cacert.pem
ADDED
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'parasut_ruby_sdk'
|
2
|
+
|
3
|
+
PARASUT_CLIENT_ID = ''
|
4
|
+
PARASUT_CLIENT_SECRET = ''
|
5
|
+
PARASUT_CALLBACK_URL = 'urn:ietf:wg:oauth:2.0:oob'
|
6
|
+
PARASUT_USERNAME = ''
|
7
|
+
PARASUT_USER_PASSWORD = ''
|
8
|
+
PARASUT_COMPANY_ID = ''
|
9
|
+
|
10
|
+
config = {
|
11
|
+
client_id: PARASUT_CLIENT_ID,
|
12
|
+
client_secret: PARASUT_CLIENT_SECRET,
|
13
|
+
callback_url: PARASUT_CALLBACK_URL,
|
14
|
+
username: PARASUT_USERNAME,
|
15
|
+
password: PARASUT_USER_PASSWORD,
|
16
|
+
company_id: PARASUT_COMPANY_ID,
|
17
|
+
access_token: nil,
|
18
|
+
refresh_token: nil
|
19
|
+
}
|
20
|
+
|
21
|
+
# Get access and refresh token
|
22
|
+
tokens = ParasutRubySdk::REST::BaseRequest.new(config).get_token
|
23
|
+
config['access_token'] = tokens.access_token
|
24
|
+
config['refresh_token'] = tokens.refresh_token
|
25
|
+
|
26
|
+
# Account
|
27
|
+
# -------------------------------------------------------------
|
28
|
+
account = ParasutRubySdk::REST::Account.new(config)
|
29
|
+
puts account.all
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module ParasutRubySdk
|
2
|
+
module Helpers
|
3
|
+
module DataHelper
|
4
|
+
|
5
|
+
##
|
6
|
+
# Convert hash to object
|
7
|
+
def convert_to_obj(hash)
|
8
|
+
open_struct = OpenStruct.new
|
9
|
+
set_open_struct_variables( open_struct, hash )
|
10
|
+
open_struct
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# Set hash variable to open_struct
|
15
|
+
# Recursive method for hash values
|
16
|
+
def set_open_struct_variables(open_struct, hash)
|
17
|
+
hash.each do |key,value|
|
18
|
+
if value.is_a? Hash
|
19
|
+
# create new open struct value
|
20
|
+
new_open_struct = OpenStruct.new
|
21
|
+
open_struct.send("#{key}=", new_open_struct)
|
22
|
+
set_open_struct_variables(new_open_struct, value)
|
23
|
+
elsif value.is_a? Array
|
24
|
+
open_struct.send("#{key}=", value)
|
25
|
+
value.each_with_index do |val, index|
|
26
|
+
if val.is_a? Hash
|
27
|
+
# create new open struct value
|
28
|
+
new_open_struct = OpenStruct.new
|
29
|
+
# set array index value variable
|
30
|
+
value[index] = new_open_struct
|
31
|
+
set_open_struct_variables(new_open_struct, val)
|
32
|
+
else
|
33
|
+
# Do nothing
|
34
|
+
# value[index] = val
|
35
|
+
end
|
36
|
+
end
|
37
|
+
else
|
38
|
+
open_struct.send("#{key}=", value)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ParasutRubySdk
|
2
|
+
module REST
|
3
|
+
class Account < BaseRequest
|
4
|
+
|
5
|
+
def initialize(*args)
|
6
|
+
super(*args)
|
7
|
+
@resource = 'accounts'
|
8
|
+
end
|
9
|
+
|
10
|
+
def all( params = {} )
|
11
|
+
prepare_request( Util::RequestType::GET, @resource, params)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get( id, params = {} )
|
15
|
+
prepare_request( Util::RequestType::GET, "#{@resource}/#{id}", params)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_transactions( id )
|
19
|
+
prepare_request( Util::RequestType::GET, "#{@resource}/#{id}/transactions", params)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
module ParasutRubySdk
|
2
|
+
module REST
|
3
|
+
class BaseRequest
|
4
|
+
attr_accessor :config
|
5
|
+
HTTP_HEADERS = {
|
6
|
+
'Accept' => 'application/json',
|
7
|
+
'Accept-Charset' => 'utf-8',
|
8
|
+
'User-Agent' => "parasut_ruby_sdk/#{ParasutRubySdk::VERSION}" " (#{RUBY_ENGINE}/#{RUBY_PLATFORM}" " #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL})"
|
9
|
+
}
|
10
|
+
|
11
|
+
def initialize(*args)
|
12
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
13
|
+
args.select! {|arg| !arg.nil?}
|
14
|
+
self.config = ParasutRubySdk::Util::Configuration.new options
|
15
|
+
@refresh_try = 0
|
16
|
+
raise ArgumentError, 'Auth token or user credentials are required' if (self.config.client_id.nil? || self.config.client_secret.nil? || self.config.username.nil? || self.config.password.nil?)
|
17
|
+
set_up_connection
|
18
|
+
get_token_from_api if self.config.access_token.nil?
|
19
|
+
end
|
20
|
+
|
21
|
+
def refresh_expired_token
|
22
|
+
refresh_token
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_token
|
26
|
+
get_token_from_api
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
##
|
31
|
+
# Set up and cache a Net::HTTP object to use when making requests.
|
32
|
+
def set_up_connection # :doc:
|
33
|
+
uri = URI.parse(self.config.host)
|
34
|
+
@http = Net::HTTP.new(uri.host, uri.port, p_user = self.config.proxy_user, p_pass = self.config.proxy_pass)
|
35
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
36
|
+
@http.use_ssl = self.config.use_ssl
|
37
|
+
if self.config.ssl_verify_peer
|
38
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
39
|
+
@http.ca_file = self.config.ssl_ca_file
|
40
|
+
else
|
41
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
42
|
+
end
|
43
|
+
@http.open_timeout = self.config.timeout
|
44
|
+
@http.read_timeout = self.config.timeout
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# Send an HTTP request using the cached <tt>@http</tt> object and
|
49
|
+
# return the JSON response body parsed into a hash. Also save the raw
|
50
|
+
# Net::HTTP::Request and Net::HTTP::Response objects as
|
51
|
+
# <tt>@last_request</tt> and <tt>@last_response</tt> to allow for
|
52
|
+
# inspection later.
|
53
|
+
def connect_and_send(request, is_file = false ) # :doc:
|
54
|
+
@last_request = request
|
55
|
+
retries_left = self.config.retry_limit
|
56
|
+
begin
|
57
|
+
response = @http.request request
|
58
|
+
@last_response = response
|
59
|
+
if response.kind_of? Net::HTTPServerError
|
60
|
+
# raise ParasutRubySdk::REST::ServerError
|
61
|
+
return response
|
62
|
+
end
|
63
|
+
rescue
|
64
|
+
raise if request.class == Net::HTTP::Post
|
65
|
+
if retries_left > 0 then retries_left -= 1; retry else raise end
|
66
|
+
end
|
67
|
+
if response.body and !response.body.empty?
|
68
|
+
if is_file
|
69
|
+
object = response.body
|
70
|
+
else
|
71
|
+
object = JSON.parse(response.body)
|
72
|
+
end
|
73
|
+
elsif response.kind_of? Net::HTTPBadRequest
|
74
|
+
object = { message: 'Bad request', code: 400 }
|
75
|
+
end
|
76
|
+
|
77
|
+
if response.kind_of? Net::HTTPClientError
|
78
|
+
# if response.kind_of? Net::HTTPUnauthorized
|
79
|
+
# object = response
|
80
|
+
# else
|
81
|
+
# object = response
|
82
|
+
# # raise ParasutRubySdk::REST::RequestError.new response.message, response.code
|
83
|
+
# end
|
84
|
+
object = response
|
85
|
+
end
|
86
|
+
object
|
87
|
+
end
|
88
|
+
|
89
|
+
##
|
90
|
+
# Prepare http request
|
91
|
+
def prepare_request(method, path, params = {})
|
92
|
+
uri = uri_parse(params, path)
|
93
|
+
uri.query = URI.encode_www_form(params) if ['get', 'delete'].include?(method)
|
94
|
+
method_class = Net::HTTP.const_get method.to_s.capitalize
|
95
|
+
headers = HTTP_HEADERS.clone
|
96
|
+
headers['Content-Type'] = 'application/json' if ['post', 'put'].include?(method)
|
97
|
+
request = method_class.new(uri.to_s, headers)
|
98
|
+
request.body = params.to_json if ['post', 'put'].include?(method)
|
99
|
+
connect_and_send(request)
|
100
|
+
end
|
101
|
+
|
102
|
+
##
|
103
|
+
# URI parse for params
|
104
|
+
def uri_parse(params = {}, path)
|
105
|
+
root_path = params.delete(:root_path)
|
106
|
+
if root_path
|
107
|
+
request_path = "#{self.config.host}/#{path}"
|
108
|
+
else
|
109
|
+
request_path = "#{self.config.host}/v1/#{self.config.company_id}/#{path}"
|
110
|
+
params[:access_token] = self.config.access_token
|
111
|
+
end
|
112
|
+
URI.parse(request_path)
|
113
|
+
end
|
114
|
+
|
115
|
+
def get_token_from_api
|
116
|
+
params = {
|
117
|
+
client_id: self.config.client_id,
|
118
|
+
client_secret: self.config.client_secret,
|
119
|
+
grant_type: 'password',
|
120
|
+
redirect_uri: self.config.callback_url,
|
121
|
+
username: self.config.username,
|
122
|
+
password: self.config.password,
|
123
|
+
root_path: true
|
124
|
+
}
|
125
|
+
credentials = prepare_request(Util::RequestType::POST, 'oauth/token', params)
|
126
|
+
set_credentials(credentials)
|
127
|
+
@refresh_try = 0
|
128
|
+
self.config
|
129
|
+
end
|
130
|
+
|
131
|
+
def set_credentials(credentials)
|
132
|
+
conf = self.config.clone
|
133
|
+
conf.access_token = credentials['access_token']
|
134
|
+
conf.refresh_token = credentials['refresh_token']
|
135
|
+
self.config = conf
|
136
|
+
self.config
|
137
|
+
end
|
138
|
+
|
139
|
+
def refresh_token
|
140
|
+
params = {
|
141
|
+
client_id: self.config.client_id,
|
142
|
+
client_secret: self.config.client_secret,
|
143
|
+
grant_type: 'refresh_token',
|
144
|
+
refresh_token: self.config.refresh_token,
|
145
|
+
root_path: true
|
146
|
+
}
|
147
|
+
credentials = prepare_request(Util::RequestType::POST, 'oauth/token', params)
|
148
|
+
set_credentials(credentials)
|
149
|
+
@refresh_try = 0
|
150
|
+
self.config
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ParasutRubySdk
|
2
|
+
module REST
|
3
|
+
class Category < BaseRequest
|
4
|
+
|
5
|
+
def initialize(*args)
|
6
|
+
super(*args)
|
7
|
+
@resource = 'item_categories'
|
8
|
+
end
|
9
|
+
|
10
|
+
def all( params = {} )
|
11
|
+
prepare_request( Util::RequestType::GET, @resource, params)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create( params )
|
15
|
+
prepare_request( Util::RequestType::POST, @resource, params)
|
16
|
+
end
|
17
|
+
|
18
|
+
def update( id, params )
|
19
|
+
prepare_request( Util::RequestType::PUT, "#{@resource}/#{id}", params)
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete( id )
|
23
|
+
prepare_request( Util::RequestType::DELETE, "#{@resource}/#{id}")
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module ParasutRubySdk
|
2
|
+
module REST
|
3
|
+
class Contact < BaseRequest
|
4
|
+
|
5
|
+
def initialize(*args)
|
6
|
+
super(*args)
|
7
|
+
@resource = 'contacts'
|
8
|
+
end
|
9
|
+
|
10
|
+
def all( params = {} )
|
11
|
+
prepare_request( Util::RequestType::GET, @resource, params)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get( id )
|
15
|
+
prepare_request( Util::RequestType::GET, "#{@resource}/#{id}")
|
16
|
+
end
|
17
|
+
|
18
|
+
def create( params )
|
19
|
+
prepare_request( Util::RequestType::POST, @resource, params)
|
20
|
+
end
|
21
|
+
|
22
|
+
def update( id, params )
|
23
|
+
prepare_request( Util::RequestType::PUT, "#{@resource}/#{id}", params)
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete( id )
|
27
|
+
prepare_request( Util::RequestType::DELETE, "#{@resource}/#{id}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def outstanding_payments( id )
|
31
|
+
prepare_request( Util::RequestType::GET, "#{@resource}/#{id}/outstanding_payments")
|
32
|
+
end
|
33
|
+
|
34
|
+
def past_transactions( id )
|
35
|
+
prepare_request( Util::RequestType::GET, "#{@resource}/#{id}/past_transactions")
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ParasutRubySdk
|
2
|
+
module REST
|
3
|
+
class ServerError < StandardError; end
|
4
|
+
|
5
|
+
class RequestError < StandardError
|
6
|
+
attr_reader :code
|
7
|
+
|
8
|
+
def initialize(message, code=nil)
|
9
|
+
super message
|
10
|
+
@code = code
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class SDKError < StandardError
|
15
|
+
attr_reader :code
|
16
|
+
|
17
|
+
def initialize(message, code=nil)
|
18
|
+
super message
|
19
|
+
@code = code
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ParasutRubySdk
|
2
|
+
module REST
|
3
|
+
class Parasut < BaseRequest
|
4
|
+
|
5
|
+
def initialize(*args)
|
6
|
+
super(*args)
|
7
|
+
@args = args.first
|
8
|
+
end
|
9
|
+
|
10
|
+
def accounts
|
11
|
+
ParasutRubySdk::REST::Account.new(@args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def contacts
|
15
|
+
ParasutRubySdk::REST::Contact.new(@args)
|
16
|
+
end
|
17
|
+
|
18
|
+
def categories
|
19
|
+
ParasutRubySdk::REST::Category.new(@args)
|
20
|
+
end
|
21
|
+
|
22
|
+
def products
|
23
|
+
ParasutRubySdk::REST::Product.new(@args)
|
24
|
+
end
|
25
|
+
|
26
|
+
def sales_invoices
|
27
|
+
ParasutRubySdk::REST::SalesInvoice.new(@args)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ParasutRubySdk
|
2
|
+
module REST
|
3
|
+
class Product < BaseRequest
|
4
|
+
|
5
|
+
def initialize(*args)
|
6
|
+
super(*args)
|
7
|
+
@resource = 'products'
|
8
|
+
end
|
9
|
+
|
10
|
+
def all( params = {} )
|
11
|
+
prepare_request( Util::RequestType::GET, @resource, params)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get( id )
|
15
|
+
prepare_request( Util::RequestType::GET, "#{@resource}/#{id}")
|
16
|
+
end
|
17
|
+
|
18
|
+
def create( params )
|
19
|
+
prepare_request( Util::RequestType::POST, @resource, params)
|
20
|
+
end
|
21
|
+
|
22
|
+
def update( id, params )
|
23
|
+
prepare_request( Util::RequestType::PUT, "#{@resource}/#{id}", params)
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete( id )
|
27
|
+
prepare_request( Util::RequestType::DELETE, "#{@resource}/#{id}")
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module ParasutRubySdk
|
2
|
+
module REST
|
3
|
+
class SalesInvoice < BaseRequest
|
4
|
+
|
5
|
+
def initialize(*args)
|
6
|
+
super(*args)
|
7
|
+
@resource = 'sales_invoices'
|
8
|
+
end
|
9
|
+
|
10
|
+
def all( params = {} )
|
11
|
+
prepare_request( Util::RequestType::GET, @resource, params)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get( id )
|
15
|
+
prepare_request( Util::RequestType::GET, "#{@resource}/#{id}")
|
16
|
+
end
|
17
|
+
|
18
|
+
def create( params )
|
19
|
+
prepare_request( Util::RequestType::POST, @resource, params)
|
20
|
+
end
|
21
|
+
|
22
|
+
def update( id, params )
|
23
|
+
prepare_request( Util::RequestType::PUT, "#{@resource}/#{id}", params)
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete( id )
|
27
|
+
prepare_request( Util::RequestType::DELETE, "#{@resource}/#{id}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def convert_to_invoice( id )
|
31
|
+
prepare_request( Util::RequestType::POST, "#{@resource}/#{id}/convert_to_invoice")
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_payments ( id, params)
|
35
|
+
prepare_request( Util::RequestType::POST, "#{@resource}/#{id}/payments", params)
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_e_document_type( id )
|
39
|
+
prepare_request( Util::RequestType::GET, "#{@resource}/#{id}/e_document_type")
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_e_invoice( id, params )
|
43
|
+
prepare_request( Util::RequestType::POST, "#{@resource}/#{id}/e_invoice", params)
|
44
|
+
end
|
45
|
+
|
46
|
+
def create_e_archive( id, params )
|
47
|
+
prepare_request( Util::RequestType::POST, "#{@resource}/#{id}/e_archive", params)
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_e_document_status( id )
|
51
|
+
prepare_request( Util::RequestType::GET, "#{@resource}/#{id}/e_document_status")
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module ParasutRubySdk
|
2
|
+
module Util
|
3
|
+
class Configuration
|
4
|
+
CONFIGS = {
|
5
|
+
host: 'https://api.parasut.com',
|
6
|
+
port: 80,
|
7
|
+
use_ssl: true,
|
8
|
+
ssl_verify_peer: false,
|
9
|
+
ssl_ca_file: File.dirname(__FILE__) + '/../../../conf/cacert.pem',
|
10
|
+
timeout: 30,
|
11
|
+
proxy_addr: nil,
|
12
|
+
proxy_port: nil,
|
13
|
+
proxy_user: nil,
|
14
|
+
proxy_pass: nil,
|
15
|
+
retry_limit: 2,
|
16
|
+
api_version: 'v1',
|
17
|
+
company_id: nil,
|
18
|
+
client_id: nil,
|
19
|
+
client_secret: nil,
|
20
|
+
callback_url: 'urn:ietf:wg:oauth:2.0:oob',
|
21
|
+
username: nil,
|
22
|
+
password: nil,
|
23
|
+
access_token: nil,
|
24
|
+
refresh_token: nil
|
25
|
+
}
|
26
|
+
|
27
|
+
CONFIGS.each_key do |attribute|
|
28
|
+
attr_accessor attribute
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize(opts={})
|
32
|
+
CONFIGS.each do |attribute, value|
|
33
|
+
send("#{attribute}=".to_sym, opts.fetch(attribute, value))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module ParasutRubySdk
|
2
|
+
module Util
|
3
|
+
class RequestType
|
4
|
+
GET = 'get'
|
5
|
+
POST = 'post'
|
6
|
+
PUT = 'put'
|
7
|
+
DELETE = 'delete'
|
8
|
+
PATCH = 'patch'
|
9
|
+
end
|
10
|
+
|
11
|
+
module Contact
|
12
|
+
module Types
|
13
|
+
PERSON = 'person'
|
14
|
+
COMPANY = 'company'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module Category
|
19
|
+
module Types
|
20
|
+
CONTACT = 'Contact'
|
21
|
+
PRODUCT = 'Product'
|
22
|
+
SALES_INVOICE = 'SalesInvoice'
|
23
|
+
PURCHASE_INVOICE = 'PurchaseInvoice'
|
24
|
+
EXPENSE = 'Expense'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module SalesInvoice
|
29
|
+
module ItemTypes
|
30
|
+
INVOICE = 'invoice'
|
31
|
+
ESTIMATE = 'estimate'
|
32
|
+
end
|
33
|
+
module PaymentStatus
|
34
|
+
UNPAID = 'unpaid'
|
35
|
+
OVERDUE = 'overdue'
|
36
|
+
PARTIALLY_PAID = 'partially_paid'
|
37
|
+
PAID = 'paid'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module EInvoice
|
42
|
+
module Scenario
|
43
|
+
BASIC = 'basic'
|
44
|
+
COMMERCIAL = 'commercial'
|
45
|
+
end
|
46
|
+
|
47
|
+
module ExciseDutyCode
|
48
|
+
PETROL = '0071'
|
49
|
+
SODA = '0073'
|
50
|
+
DURABLE = '0074'
|
51
|
+
ALCOHOL = '0075'
|
52
|
+
TOBACCO = '0076'
|
53
|
+
SODA2 = '0077'
|
54
|
+
MOTORIZED = '9077'
|
55
|
+
end
|
56
|
+
|
57
|
+
module InternetSale
|
58
|
+
CREDIT_CARD = 'KREDIKARTI/BANKAKARTI'
|
59
|
+
EFT = 'EFT/HAVALE'
|
60
|
+
AT_THE_DOOR = 'KAPIDAODEME'
|
61
|
+
AGENT = 'ODEMEARACISI'
|
62
|
+
OTHER = 'DIGER'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require 'parasut_ruby_sdk/version'
|
5
|
+
require 'parasut_ruby_sdk/helpers/data_helper'
|
6
|
+
require 'parasut_ruby_sdk/hash'
|
7
|
+
require 'parasut_ruby_sdk/util/configuration'
|
8
|
+
require 'parasut_ruby_sdk/util/request_type'
|
9
|
+
require 'parasut_ruby_sdk/rest/base_request'
|
10
|
+
require 'parasut_ruby_sdk/rest/account'
|
11
|
+
require 'parasut_ruby_sdk/rest/category'
|
12
|
+
require 'parasut_ruby_sdk/rest/contact'
|
13
|
+
require 'parasut_ruby_sdk/rest/errors'
|
14
|
+
require 'parasut_ruby_sdk/rest/parasut'
|
15
|
+
require 'parasut_ruby_sdk/rest/product'
|
16
|
+
require 'parasut_ruby_sdk/rest/sales_invoice'
|
17
|
+
|
18
|
+
include ParasutRubySdk::Helpers::DataHelper
|
19
|
+
|
20
|
+
module ParasutRubySdk
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'parasut_ruby_sdk/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'parasut_ruby_sdk'
|
8
|
+
spec.version = ParasutRubySdk::VERSION
|
9
|
+
spec.authors = ['Lab2023']
|
10
|
+
spec.email = ['info@lab2023.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Paraşüt SDK}
|
13
|
+
spec.description = %q{Paraşüt SDK}
|
14
|
+
spec.homepage = 'https://github.com/lab2023/parasut-ruby-sdk'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: parasut_ruby_sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lab2023
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Paraşüt SDK
|
42
|
+
email:
|
43
|
+
- info@lab2023.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- bin/console
|
53
|
+
- bin/setup
|
54
|
+
- conf/cacert.pem
|
55
|
+
- examples/examples.rb
|
56
|
+
- lib/parasut_ruby_sdk.rb
|
57
|
+
- lib/parasut_ruby_sdk/hash.rb
|
58
|
+
- lib/parasut_ruby_sdk/helpers/data_helper.rb
|
59
|
+
- lib/parasut_ruby_sdk/rest/account.rb
|
60
|
+
- lib/parasut_ruby_sdk/rest/base_request.rb
|
61
|
+
- lib/parasut_ruby_sdk/rest/category.rb
|
62
|
+
- lib/parasut_ruby_sdk/rest/contact.rb
|
63
|
+
- lib/parasut_ruby_sdk/rest/errors.rb
|
64
|
+
- lib/parasut_ruby_sdk/rest/parasut.rb
|
65
|
+
- lib/parasut_ruby_sdk/rest/product.rb
|
66
|
+
- lib/parasut_ruby_sdk/rest/sales_invoice.rb
|
67
|
+
- lib/parasut_ruby_sdk/util/configuration.rb
|
68
|
+
- lib/parasut_ruby_sdk/util/request_type.rb
|
69
|
+
- lib/parasut_ruby_sdk/version.rb
|
70
|
+
- parasut_ruby_sdk.gemspec
|
71
|
+
homepage: https://github.com/lab2023/parasut-ruby-sdk
|
72
|
+
licenses: []
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.6.7
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Paraşüt SDK
|
94
|
+
test_files: []
|