nusii 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +306 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/lib/nusii.rb +54 -0
- data/lib/nusii/account.rb +18 -0
- data/lib/nusii/api_operations/base.rb +58 -0
- data/lib/nusii/api_operations/connection.rb +21 -0
- data/lib/nusii/api_operations/create.rb +30 -0
- data/lib/nusii/api_operations/delete.rb +30 -0
- data/lib/nusii/api_operations/index.rb +37 -0
- data/lib/nusii/api_operations/nested_create.rb +31 -0
- data/lib/nusii/api_operations/nested_index.rb +27 -0
- data/lib/nusii/api_operations/send.rb +29 -0
- data/lib/nusii/api_operations/show.rb +32 -0
- data/lib/nusii/api_operations/update.rb +30 -0
- data/lib/nusii/client.rb +24 -0
- data/lib/nusii/crud/create.rb +12 -0
- data/lib/nusii/crud/destroy.rb +12 -0
- data/lib/nusii/crud/destroy_self.rb +14 -0
- data/lib/nusii/crud/get.rb +12 -0
- data/lib/nusii/crud/list.rb +12 -0
- data/lib/nusii/crud/save.rb +23 -0
- data/lib/nusii/line_item.rb +37 -0
- data/lib/nusii/nusii_error.rb +48 -0
- data/lib/nusii/proposal.rb +31 -0
- data/lib/nusii/proposal_activity.rb +17 -0
- data/lib/nusii/request.rb +45 -0
- data/lib/nusii/resource.rb +40 -0
- data/lib/nusii/response_object.rb +29 -0
- data/lib/nusii/section.rb +25 -0
- data/lib/nusii/utils/json_api_builder.rb +69 -0
- data/lib/nusii/version.rb +3 -0
- data/lib/nusii/webhook_endpoint.rb +23 -0
- data/nusii.gemspec +33 -0
- metadata +194 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 03c6d3347ec4b9e09b5ccd2e2efc2ba4aa1a3311641acce82aebaf1f3b699960
|
4
|
+
data.tar.gz: f57f750cafed39f795bcbb588062993536d4bd70c455e25b3685c62b9d1ef4d7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 15d7ac2715ed3cda572f48550628feb58d152a1c2b8b722c2c9b64999d354b9d56e5b97b5fc32c48b18a929a0b3e91d1e0a5b8b82c8a6035a27e1459002537ea
|
7
|
+
data.tar.gz: 3e9c10b362c22bfddec18612c7b811fa7df47489e019e350ce0cdc028d42b8a89a7ad3f593839588405a0e08d7af3c6a41dbbf3a7162f0bdc203ac1dd29b07e1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Nusii
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,306 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/Nusii/nusii-ruby.png)](https://travis-ci.org/Nusii/nusii-ruby)
|
2
|
+
|
3
|
+
# Nusii
|
4
|
+
|
5
|
+
Ruby library for the [Nusii API](https://developer.nusii.com)
|
6
|
+
|
7
|
+
## Table of contents
|
8
|
+
|
9
|
+
* [Installation](#installation)
|
10
|
+
* [Setup](#setup)
|
11
|
+
* [Example usage](#example-usage)
|
12
|
+
* [Available methods by resource](#available-methods-by-resource)
|
13
|
+
* [Contributing](#contributing)
|
14
|
+
* [Usage](#contributing)
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
To get the latest stable, add this to your Gemfile:
|
19
|
+
|
20
|
+
gem 'nusii'
|
21
|
+
|
22
|
+
To get the latest code, add this:
|
23
|
+
|
24
|
+
gem 'nusii', git: https://github.com/Nusii/nusii-ruby
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
$ bundle
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
|
32
|
+
$ gem install nusii
|
33
|
+
|
34
|
+
## Setup
|
35
|
+
|
36
|
+
The only thing you need to do is add you API KEY:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require 'nusii-ruby'
|
40
|
+
|
41
|
+
Nusii.setup(:api_key => 'YOUR_API_KEY', :user_agent => 'your_user_agent')
|
42
|
+
```
|
43
|
+
|
44
|
+
## Example usage
|
45
|
+
|
46
|
+
### Listing resources
|
47
|
+
|
48
|
+
Use .list to retrieve a list of a resource
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
> Nusii::Client.list
|
52
|
+
=> #<Nusii::ResponseObject:0x007fadfb6d8ac0
|
53
|
+
@meta={"current_page"=>1, "next_page"=>2, "prev_page"=>nil, "total_pages"=>2, "total_count"=>29},
|
54
|
+
@resource_class=Nusii::Client,
|
55
|
+
@resources=
|
56
|
+
[#<Nusii::Client:0x007fadfb6eb468
|
57
|
+
@currency="USD",
|
58
|
+
@email="martin@madeupcompany.com",
|
59
|
+
@full_name="Martin",
|
60
|
+
@id=35843,
|
61
|
+
@locale="en",
|
62
|
+
@name="Martin",
|
63
|
+
@pdf_page_size="A4">,
|
64
|
+
... ]
|
65
|
+
```
|
66
|
+
|
67
|
+
You can also pass options such as `page` or `per`:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
> Nusii::Client.list(:per => 2, :page => 4)
|
71
|
+
=> #<Nusii::ResponseObject:0x007fadfb530c40
|
72
|
+
@meta={"current_page"=>4, "next_page"=>5, "prev_page"=>3, "total_pages"=>15, "total_count"=>29},
|
73
|
+
@resource_class=Nusii::Client,
|
74
|
+
@resources=
|
75
|
+
[#<Nusii::Client:0x007fadfb5313c0
|
76
|
+
@currency="USD",
|
77
|
+
@email="victor@madeupcompany.com",
|
78
|
+
@full_name="Victor",
|
79
|
+
@id=35835,
|
80
|
+
@locale="es",
|
81
|
+
@name="Victor",
|
82
|
+
@pdf_page_size="A4">,
|
83
|
+
#<Nusii::Client:0x007fadfb530e20
|
84
|
+
@currency="EUR",
|
85
|
+
@email="altheasmith@madeupcompany.com",
|
86
|
+
@full_name="Althea",
|
87
|
+
@id=35834,
|
88
|
+
@locale="en",
|
89
|
+
@name="Althea",
|
90
|
+
@pdf_page_size="A4">]>
|
91
|
+
```
|
92
|
+
|
93
|
+
|
94
|
+
Any ResponseObject instance also has the methods `next_page` and `prev_page` which will automatically make the requests based on the current search.
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
> response = Nusii::Client.list(:per => 4, :page => 2)
|
98
|
+
=> #<Nusii::ResponseObject:0x007fadfb0bd028
|
99
|
+
@meta={"current_page"=>2, "next_page"=>3, "prev_page"=>1, "total_pages"=>8, "total_count"=>29},
|
100
|
+
@resource_class=Nusii::Client,
|
101
|
+
@resources= [...]
|
102
|
+
|
103
|
+
> response.prev_page
|
104
|
+
=> #<Nusii::ResponseObject:0x007f8df2c3b518
|
105
|
+
@meta={"current_page"=>1, "next_page"=>2, "prev_page"=>nil, "total_pages"=>8, "total_count"=>29},
|
106
|
+
@resource_class=Nusii::Client,
|
107
|
+
@resources=[...]
|
108
|
+
```
|
109
|
+
|
110
|
+
`Nusii::ListItem` has also a method called `.list_by_section` that accepts a `section_id` as the first argument and retrieves ListItems under that section_id
|
111
|
+
|
112
|
+
### Getting a single resource
|
113
|
+
|
114
|
+
Use `.get` to retrieve a single resource
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
> Nusii::Section.get 309405
|
118
|
+
=> #<Nusii::Section:0x007f8df3020778
|
119
|
+
@id=309405,
|
120
|
+
@body=
|
121
|
+
"<p>We are a web design studio with offices in Madrid and Barcelona and we're lucky enough to work with people from all over the world./p>",
|
122
|
+
@currency="EUR",
|
123
|
+
@include_total=false,
|
124
|
+
@name="Introduction",
|
125
|
+
...">
|
126
|
+
```
|
127
|
+
|
128
|
+
### Creating and updating resources
|
129
|
+
|
130
|
+
You can create a resource with the class method `.create` by passing a hash of arguments:
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
> Nusii::Client.create({:name => 'Laura Palmer', :email => 'laura.palmer@tphs.com'})
|
134
|
+
=> #<Nusii::Client:0x007f8df2b6aa58
|
135
|
+
@currency="USD",
|
136
|
+
@email="laura.palmer@tphs.com",
|
137
|
+
@full_name="Laura Palmer",
|
138
|
+
@id=35947,
|
139
|
+
@locale="en",
|
140
|
+
@name="Laura Palmer",
|
141
|
+
@pdf_page_size="A4">
|
142
|
+
```
|
143
|
+
|
144
|
+
You can also create them by using `#save` on a new object:
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
client = Nusii::Client.new({:name => 'Laura Palmer', :email => 'laura.palmer@tphs.com'})
|
148
|
+
=> #<Nusii::Client:0x007f8df2b226e0 @email="laura.palmer@tphs.com", @name="Laura Palmer">
|
149
|
+
> client.save
|
150
|
+
=> #<Nusii::Client:0x007f8df2abacc0
|
151
|
+
@currency="USD",
|
152
|
+
@email="laura.palmer@tphs.com",
|
153
|
+
@full_name="Laura Palmer",
|
154
|
+
@id=35948,
|
155
|
+
@locale="en",
|
156
|
+
@name="Laura Palmer",
|
157
|
+
@pdf_page_size="A4">
|
158
|
+
```
|
159
|
+
|
160
|
+
Any resource with a valid `id` value can be updated with the same method, `#save`.
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
> client.name = 'Sheryl Lee'
|
164
|
+
=> "Sheryl Lee"
|
165
|
+
> client.save
|
166
|
+
=> #<Nusii::Client:0x007f8df21521b0
|
167
|
+
@currency="USD",
|
168
|
+
@email="laura.palmer@tphs.com",
|
169
|
+
@full_name="Sheryl Lee",
|
170
|
+
@id=35949,
|
171
|
+
@locale="en",
|
172
|
+
@name="Sheryl Lee",
|
173
|
+
@pdf_page_size="A4">
|
174
|
+
```
|
175
|
+
|
176
|
+
### Deleting resources
|
177
|
+
|
178
|
+
Just as happens with creation, a resource can be deleted by a class method `.destroy` passign a valid id or with `#destroy` on a instance.
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
> Nusii::WebhookEndpoint.destroy(54)
|
182
|
+
=> true
|
183
|
+
```
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
> webhook = Nusii::WebhookEndpoint.get(55)
|
187
|
+
=> #<Nusii::WebhookEndpoint:0x007f8df2302a28 @events=["proposal_updated"], @id=55, @target_url="http://example.com">
|
188
|
+
> webhook.destroy
|
189
|
+
=> true
|
190
|
+
```
|
191
|
+
|
192
|
+
### Sending a proposal
|
193
|
+
|
194
|
+
With any `Proposal` object you can use the method `#send_proposal`. You need to pass at least the email of the client you want the existing proposal sent to. Please [refer to the API](https://developer.nusii.com/#send-a-proposal) for more information.
|
195
|
+
|
196
|
+
```ruby
|
197
|
+
> proposal.send_proposal(:email => 'lucas.tazmily@myclient.com')
|
198
|
+
=> {"status"=>"pending", "sent_at"=>"2017-12-11T12:37:12.593Z", "sent_at_in_ms"=>1512995832000, "sender_id"=>nil, "sender_name"=>nil}
|
199
|
+
```
|
200
|
+
|
201
|
+
### Retrieving account information
|
202
|
+
|
203
|
+
Use `Account.me` to get the information from your account
|
204
|
+
|
205
|
+
```ruby
|
206
|
+
> Nusii::Account.me
|
207
|
+
=> #<Nusii::Account:0x007fb042f30350
|
208
|
+
@address="Calle Mayor, 23",
|
209
|
+
@city="Madrid",
|
210
|
+
@country="Spain",
|
211
|
+
@country_name="Spain",
|
212
|
+
@currency="EUR",
|
213
|
+
@email="michael@test.com",
|
214
|
+
@id=44,
|
215
|
+
@name="Michael Account",
|
216
|
+
@postcode="28017",
|
217
|
+
@subdomain="michael",
|
218
|
+
@telephone="123456789",
|
219
|
+
@web="nusii.com">
|
220
|
+
```
|
221
|
+
|
222
|
+
### Rate limiting
|
223
|
+
|
224
|
+
There is a rate limit in Nusii API of 100 requests every 30 seconds. After every request, a class variable in `Nusii` will get updated so you can check if you are reaching the limit
|
225
|
+
|
226
|
+
```ruby
|
227
|
+
> Nusii.rate_limit_remaining
|
228
|
+
=> 98
|
229
|
+
> Nusii::Account.me
|
230
|
+
=> #<Nusii::Account:0x007f8df20fa028 ...>
|
231
|
+
> Nusii.rate_limit_remaining
|
232
|
+
=> 97
|
233
|
+
```
|
234
|
+
|
235
|
+
There's another variable called `rate_limit_retry_after` that will store the amount of time, in seconds, that you have to wait if you have reached the limit.
|
236
|
+
|
237
|
+
## Available methods by resource
|
238
|
+
|
239
|
+
#### Account
|
240
|
+
|
241
|
+
* Nusii::Account.me
|
242
|
+
|
243
|
+
#### Clients
|
244
|
+
|
245
|
+
* Nusii::Client.list
|
246
|
+
* Nusii::Client.get
|
247
|
+
* Nusii::Client.create
|
248
|
+
* Nusii::Client#save
|
249
|
+
* Nusii::Client.destroy
|
250
|
+
* Nusii::Client#destroy
|
251
|
+
|
252
|
+
#### Sections
|
253
|
+
|
254
|
+
* Nusii::Section.list
|
255
|
+
* Nusii::Section.get
|
256
|
+
* Nusii::Section.create
|
257
|
+
* Nusii::Section#save
|
258
|
+
* Nusii::Section.destroy
|
259
|
+
* Nusii::Section#destroy
|
260
|
+
|
261
|
+
#### Line Items
|
262
|
+
|
263
|
+
* Nusii::LineItem.list
|
264
|
+
* Nusii::LineItem.list_by_section
|
265
|
+
* Nusii::LineItem.create_with_section
|
266
|
+
* Nusii::LineItem#save
|
267
|
+
* Nusii::LineItem.destroy
|
268
|
+
* Nusii::LineItem#destroy
|
269
|
+
|
270
|
+
#### Proposals
|
271
|
+
|
272
|
+
* Nusii::Proposal.list
|
273
|
+
* Nusii::Proposal.get
|
274
|
+
* Nusii::Proposal.create
|
275
|
+
* Nusii::Proposal#save
|
276
|
+
* Nusii::Proposal.destroy
|
277
|
+
* Nusii::Proposal#destroy
|
278
|
+
* Nusii::Proposal#send_proposal
|
279
|
+
|
280
|
+
#### Proposal Activities
|
281
|
+
|
282
|
+
* Nusii::Proposal.list
|
283
|
+
* Nusii::Proposal.get
|
284
|
+
|
285
|
+
#### Webhook Enpoints
|
286
|
+
|
287
|
+
* Nusii::WebhookEndpoint.list
|
288
|
+
* Nusii::WebhookEndpoint.get
|
289
|
+
* Nusii::WebhookEndpoint.create
|
290
|
+
* Nusii::WebhookEndpoint#save
|
291
|
+
* Nusii::WebhookEndpoint.destroy
|
292
|
+
* Nusii::WebhookEndpoint#destroy
|
293
|
+
|
294
|
+
## Contributing
|
295
|
+
|
296
|
+
If you want to contribute, please follow these easy steps:
|
297
|
+
|
298
|
+
1. Fork it ( http://github.com/nusii/nusii-ruby/fork )
|
299
|
+
2. Create your feature branch (`git checkout -b improving-something`)
|
300
|
+
3. Commit your changes (`git commit -am 'Let's improve this!'`)
|
301
|
+
4. Push to the branch (`git push origin improving-something`)
|
302
|
+
5. Create new Pull Request
|
303
|
+
|
304
|
+
## License
|
305
|
+
|
306
|
+
Released under the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/lib/nusii.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'active_support/core_ext/module/delegation'
|
2
|
+
require 'active_support/core_ext/object/blank'
|
3
|
+
require 'active_support/inflector'
|
4
|
+
require 'faraday'
|
5
|
+
require 'json'
|
6
|
+
require 'pry'
|
7
|
+
|
8
|
+
require "nusii/version"
|
9
|
+
|
10
|
+
require 'nusii/api_operations/connection'
|
11
|
+
require 'nusii/api_operations/base'
|
12
|
+
require 'nusii/api_operations/show'
|
13
|
+
require 'nusii/api_operations/index'
|
14
|
+
require 'nusii/api_operations/nested_index'
|
15
|
+
require 'nusii/api_operations/create'
|
16
|
+
require 'nusii/api_operations/nested_create'
|
17
|
+
require 'nusii/api_operations/update'
|
18
|
+
require 'nusii/api_operations/delete'
|
19
|
+
require 'nusii/api_operations/send'
|
20
|
+
|
21
|
+
require 'nusii/crud/get'
|
22
|
+
require 'nusii/crud/list'
|
23
|
+
require 'nusii/crud/create'
|
24
|
+
require 'nusii/crud/save'
|
25
|
+
require 'nusii/crud/destroy'
|
26
|
+
require 'nusii/crud/destroy_self'
|
27
|
+
|
28
|
+
require 'nusii/utils/json_api_builder'
|
29
|
+
|
30
|
+
require 'nusii/nusii_error'
|
31
|
+
require 'nusii/request'
|
32
|
+
require 'nusii/response_object'
|
33
|
+
require 'nusii/resource'
|
34
|
+
require 'nusii/account'
|
35
|
+
require 'nusii/client'
|
36
|
+
require 'nusii/line_item'
|
37
|
+
require 'nusii/proposal'
|
38
|
+
require 'nusii/proposal_activity'
|
39
|
+
require 'nusii/section'
|
40
|
+
require 'nusii/webhook_endpoint'
|
41
|
+
|
42
|
+
module Nusii
|
43
|
+
extend self
|
44
|
+
|
45
|
+
class << self
|
46
|
+
attr_accessor :api_key, :user_agent,
|
47
|
+
:rate_limit_remaining, :rate_limit_retry_after
|
48
|
+
|
49
|
+
def setup params
|
50
|
+
@api_key = params[:api_key]
|
51
|
+
@user_agent = params[:user_agent]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Nusii
|
2
|
+
class Account < Resource
|
3
|
+
|
4
|
+
attr_reader :id, :email, :name, :subdomain, :web, :currency,
|
5
|
+
:pdf_page_size, :locale, :address, :address_state,
|
6
|
+
:postcode, :city, :telephone, :default_theme
|
7
|
+
|
8
|
+
def self.me
|
9
|
+
requester = Nusii::Request.new
|
10
|
+
requester.show_call self
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.resource_path
|
14
|
+
"/api/v2/account/me"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|