unleashed 0.1.5 → 0.1.6

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
  SHA256:
3
- metadata.gz: b8cf451e716eaf53fdd1c508701a506625f9d10f62a26cb7298e8b32a9832dc0
4
- data.tar.gz: ed27ce803188bbaf52c87161d5adff85a9706a7f96d836e688199b1e622d88b1
3
+ metadata.gz: 9fecd731ad21c9865bf063762b3ef5a61b36a1a05a732939aabb1bc25c3f0113
4
+ data.tar.gz: 168ecfdb748724ef08bdc61fda96df7db734ff51998c13571a87f72ce59de1f5
5
5
  SHA512:
6
- metadata.gz: ce74137ff724c846b635cc790f0031143ceb8dbc40cccff2e2e8b5db1bbcf5ff8d6401063130022583a8e69c2feccbb6894471339e6d7857973754103c6bceb8
7
- data.tar.gz: c23906fd924b35d65cca03a2df50cc88a09a8503a6708b16b379b9a238b92e88824042fa86b503c248de1005079f1ef86f03fe5de73987837bbfbfde08df26fe
6
+ metadata.gz: e9200bb879c2838c675315f5adbe0ceffbcfa5ff6f11a10eede2c619f0f6ef254565625363c515fa5fd2609dc5ce9085d6935dbbd5a329712303224184b564e5
7
+ data.tar.gz: be8b6c15381094f97e42d59894519dd3b86c4587df0eec55d3a7347362945815fa0e6c1181fede9fc19653ec60c59f7504583d47ebaa010f8ec25bf4293257e6
data/.rspec CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  --format documentation
3
2
  --color
4
3
  --require spec_helper
data/.ruby-version CHANGED
@@ -1,2 +1 @@
1
-
2
1
  2.5.0
data/.travis.yml CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  sudo: false
3
2
  language: ruby
4
3
  rvm:
data/CHANGELOG.md CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  # Change Log
3
2
 
4
3
  All notable changes to this project will be documented in this file.
data/CODE_OF_CONDUCT.md CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  # Contributor Covenant Code of Conduct
3
2
 
4
3
  ## Our Pledge
data/LICENSE CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  MIT License
3
2
 
4
3
  Copyright (c) 2019 Nathan
data/LICENSE.txt CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  The MIT License (MIT)
3
2
 
4
3
  Copyright (c) 2019 Nhan Nguyen
data/README.md CHANGED
@@ -24,7 +24,7 @@ Before interacting with Unleashed API you need to sign up an account.
24
24
 
25
25
  See [Unleashed API Documentation](https://apidocs.unleashedsoftware.com/) for more information.
26
26
 
27
- ### Create a Unleashed client
27
+ ### Setup environment variables
28
28
 
29
29
  The client can be configured through environment variables.
30
30
 
@@ -45,9 +45,17 @@ The following parameters are configurable through the client:
45
45
  * `:api_key` / `ENV['UNLEASHED_API_KEY']`: API KEY
46
46
  * `:client_type_header` / `ENV['UNLEASHED_CLIENT_TYPE_HEADER']`: Client Type Header to use (default: 'API-Sandbox')
47
47
 
48
+ ### Setup default Unleashed client from environment variables
49
+
50
+ Add file `unleashed.rb` to `config/initializers`
51
+
52
+ ```ruby
53
+ Unleashed.setup
54
+ ```
55
+
48
56
  ## 3. Usage
49
57
 
50
- ### Instantiate the Unleashed client
58
+ ### Instantiate the Unleashed client manually
51
59
 
52
60
  ```ruby
53
61
  options = { api_id: ENV['UNLEASHED_API_ID'], api_key: ENV['UNLEASHED_API_KEY'] }
@@ -68,6 +76,32 @@ client.customers.all
68
76
  client.customers.find('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX')
69
77
  ```
70
78
 
79
+ #### Get the first customer
80
+
81
+ ```ruby
82
+ client.customers.first
83
+ ```
84
+
85
+ #### Get the last customer
86
+
87
+ ```ruby
88
+ client.customers.last
89
+ ```
90
+
91
+ ### Invoices
92
+
93
+ #### Get all invoices
94
+
95
+ ```ruby
96
+ client.invoices.all
97
+ ```
98
+
99
+ #### Get an invoice
100
+
101
+ ```ruby
102
+ client.invoices.find('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX')
103
+ ```
104
+
71
105
  ## 4. Contributing
72
106
 
73
107
  1. Fork it [https://github.com/nnhansg/unleashed-ruby](https://github.com/nnhansg/unleashed-ruby)
data/Rakefile CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  require 'bundler/gem_tasks'
3
2
  require 'rspec/core/rake_task'
4
3
 
@@ -2,8 +2,10 @@ require_relative 'configurable'
2
2
  require_relative 'error'
3
3
  require_relative 'models/base_model'
4
4
  require_relative 'models/customer'
5
+ require_relative 'models/invoice'
5
6
  require_relative 'resources/base_resource'
6
7
  require_relative 'resources/customer_resource'
8
+ require_relative 'resources/invoice_resource'
7
9
  require 'json'
8
10
  require 'faraday'
9
11
 
@@ -69,66 +71,13 @@ module Unleashed
69
71
  response
70
72
  end
71
73
 
72
- # # Make a HTTP POST request
73
- # #
74
- # # @param url [String] The path, relative to {#api_endpoint}
75
- # # @param parameters [Hash] Query params for request
76
- # # @return [Faraday::Response]
77
- # def post(url, parameters = {})
78
- # response = connection.post do |req|
79
- # req.url "#{api_endpoint}#{url}"
80
- # req.headers['Content-Type'] = 'application/json'
81
- # req.body = parameters.to_json
82
- # end
83
- # on_complete(response)
84
- # response
85
- # end
86
-
87
- # # Make a HTTP PATCH request
88
- # #
89
- # # @param url [String] The path, relative to {#api_endpoint}
90
- # # @param parameters [Hash] Query params for request
91
- # # @return [Faraday::Response]
92
- # def patch(url, parameters = {})
93
- # response = connection.patch do |req|
94
- # req.url "#{api_endpoint}#{url}"
95
- # req.headers['Content-Type'] = 'application/json'
96
- # req.body = parameters.to_json
97
- # end
98
- # on_complete(response)
99
- # response
100
- # end
101
-
102
- # # Make a HTTP DELETE request
103
- # #
104
- # # @param url [String] The path, relative to {#api_endpoint}
105
- # # @param parameters [Hash] Query params for request
106
- # # @return [Faraday::Response]
107
- # def delete(url, parameters = {})
108
- # response = connection.delete do |req|
109
- # req.url "#{api_endpoint}#{url}"
110
- # req.headers['Content-Type'] = 'application/json'
111
- # req.body = parameters.to_json
112
- # end
113
- # on_complete(response)
114
- # response
115
- # end
116
-
117
- # Show details of your Platform.
118
- #
119
- # @see https://reference.Unleashed.com/#show-marketplace
120
- #
121
- # @return [Hash]
122
- def marketplace
123
- JSON.parse(get('marketplace').body)['marketplaces']
124
- end
125
-
126
74
  # Available resources for {Client}
127
75
  #
128
76
  # @return [Hash]
129
77
  def self.resources
130
78
  {
131
- customers: CustomerResource
79
+ customers: CustomerResource,
80
+ invoices: InvoiceResource
132
81
  }
133
82
  end
134
83
 
@@ -3,6 +3,7 @@ module Unleashed
3
3
  module Configurable
4
4
  attr_accessor :api_domain, :api_id, :api_key, :client_type_header, :errors_format
5
5
 
6
+ # Class Configurable
6
7
  class << self
7
8
  # List of configurable keys for {Unleashed::Client}.
8
9
  #
@@ -1,4 +1,3 @@
1
-
2
1
  module Unleashed
3
2
  # Manage Customers
4
3
  class Customer < BaseModel
@@ -0,0 +1,6 @@
1
+ module Unleashed
2
+ # Manage Invoices
3
+ class Invoice < BaseModel
4
+ end
5
+ end
6
+
@@ -34,5 +34,19 @@ module Unleashed
34
34
  response = JSON.parse(@client.get("Customers/#{id}").body)
35
35
  Unleashed::Customer.new(@client, response)
36
36
  end
37
+
38
+ # Get a first customer in all
39
+ #
40
+ # @return [Unleashed::Customer]
41
+ def first
42
+ all.first
43
+ end
44
+
45
+ # Get a last customer in all
46
+ #
47
+ # @return [Unleashed::Customer]
48
+ def last
49
+ all.last
50
+ end
37
51
  end
38
52
  end
@@ -0,0 +1,39 @@
1
+ module Unleashed
2
+ # Resource for the Invoices API
3
+ # The Invoices resource allows sales invoices to be listed and viewed.
4
+ # An individual sales invoice details can be viewed by appending its identifier
5
+ # (a GUID formatted as XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX) to the URI.
6
+ #
7
+ # @see https://apidocs.unleashedsoftware.com/Invoices
8
+ class InvoiceResource < BaseResource
9
+ def model
10
+ Unleashed::Invoice
11
+ end
12
+
13
+ # List all invoices
14
+ # /Invoices - also returns the first 200 invoices because page number 1 is the default.
15
+ #
16
+ # @param options [Hash] Optional options.
17
+ # @option options [Integer] :page_size Can ask for up to 200 invoices. default: 10
18
+ # @option options [Integer] :page Page index. default: 1
19
+ #
20
+ # @return [Array<Unleashed::Invoice>] List all invoices.
21
+ def all(options = { page: 1, page_size: 10 })
22
+ response = JSON.parse(@client.get('Invoices', options).body)
23
+ invoices = response.key?('Items') ? response['Items'] : []
24
+ invoices.map { |attributes| Unleashed::Invoice.new(@client, attributes) }
25
+ end
26
+
27
+ # Get a single invoice
28
+ # /Invoices/E6E8163F-6911-40e9-B740-90E5A0A3A996 - returns details of a particular invoice.
29
+ #
30
+ # @param id [String] invoice ID.
31
+ #
32
+ # @return [Unleashed::Invoice]
33
+ def find(id)
34
+ response = JSON.parse(@client.get("Invoices/#{id}").body)
35
+ Unleashed::Invoice.new(@client, response)
36
+ end
37
+ end
38
+ end
39
+
@@ -2,7 +2,7 @@ module Unleashed
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 5
5
+ TINY = 6
6
6
 
7
7
  STRING = "#{MAJOR}.#{MINOR}.#{TINY}".freeze
8
8
  end
data/unleashed.gemspec CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'unleashed/version'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unleashed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nhan Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-11 00:00:00.000000000 Z
11
+ date: 2019-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -115,8 +115,10 @@ files:
115
115
  - lib/unleashed/error.rb
116
116
  - lib/unleashed/models/base_model.rb
117
117
  - lib/unleashed/models/customer.rb
118
+ - lib/unleashed/models/invoice.rb
118
119
  - lib/unleashed/resources/base_resource.rb
119
120
  - lib/unleashed/resources/customer_resource.rb
121
+ - lib/unleashed/resources/invoice_resource.rb
120
122
  - lib/unleashed/version.rb
121
123
  - unleashed.gemspec
122
124
  homepage: https://github.com/nnhansg/unleashed-ruby