easybill-api 0.7.0 → 0.7.1

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
  SHA1:
3
- metadata.gz: 248667940e7669f77cbfb550702bb30bd0ab79b1
4
- data.tar.gz: dd1131db72ba0a6aa8450b1b1db2b55b6267f66e
3
+ metadata.gz: a9fbb2b594d462f64e79bb212a2c0175a6a031ab
4
+ data.tar.gz: c4d555d86a682613005cc535b243653b3a6b4b2e
5
5
  SHA512:
6
- metadata.gz: 04e9257af421c8d99a472fda6b4a0ce3a5fac8b4a2168df4564b888b0c71cc184340c3599f40abc30fbabbdcf9f531ee622c2404479263ab62d72826c8ef6942
7
- data.tar.gz: e7fa8ecc3bc1a4abd8274373355f76752a155c36915e71891f70c7a9cc23550ec979e077d54d82ea36280216af9a5abda3632d0f60b1477c8be66e0d4f39fe40
6
+ metadata.gz: 201e827dab9e7318700b08f42862cf6771a8c118401cc033f819c06eb35923aab6786487fb2839455228da7d546e63fb1d07f04828e65680df312bf7f380df1d
7
+ data.tar.gz: 84391415d0eea401203523f9267a69702ab55996eed0928db2af7576dc13b79adcf5feed31bf949b0bfd1019f77b1071065f0acf08133ca9a7e19ef4fc271e94
data/README.md CHANGED
@@ -20,21 +20,57 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
-
24
23
  Initialize a new api client:
25
24
 
26
25
  ```
27
26
  @api = Easybill::Api.new(<YOUR API TOKEN>)
28
27
  ```
29
28
 
29
+ Example calls based on the `customers` resource:
30
+
31
+ ```
32
+ # Fetch all customers
33
+
34
+ customers = @api.customers.list["items"]
35
+ ```
36
+
37
+ ```
38
+ # Fetch one customers
39
+
40
+ customer = @api.customers.find(<ID>)
41
+ fist_name = response["first_name"]
42
+ ```
43
+
30
44
  ```
31
- @api.customers.list
32
- => Fetch all customers
45
+ # Create a customer
46
+
47
+ customer_hash = {
48
+ first_name: "fabio",
49
+ last_name: "lorenzo",
50
+ ...
51
+ }
52
+
53
+ customer = @api.customers.create(customer_hash)
54
+ # => 201 created
33
55
  ```
34
56
 
35
57
  ```
36
- @api.customers.find(<ID>)
37
- => Fetch one customers
58
+ # Update a customer
59
+
60
+ update_customer_hash = {
61
+ country: "UK",
62
+ ...
63
+ }
64
+
65
+ customer = @api.customers.update(<ID>, update_customer_hash)
66
+ # => 200 ok
67
+ ```
68
+
69
+ ```
70
+ # Delete a customer
71
+
72
+ @api.customers.destroy(<ID>)
73
+ # => 204 deleted
38
74
  ```
39
75
 
40
76
  ## Development
@@ -2,6 +2,18 @@ require 'httparty'
2
2
 
3
3
  module Easybill
4
4
  module Api
5
+
6
+ ##
7
+ # The base class for all Easybill entities.
8
+ # Set the authorization header before using it via `.authenticate`
9
+ #
10
+ # Sets the default headers:
11
+ # "User-Agent" => "Ruby.Easybill.Api",
12
+ # "Accept" => "application/json",
13
+ # "Content-Type" => "application/json"
14
+ #
15
+ # Provides the basic interface. Such as list, find, create, update, destroy
16
+
5
17
  class Base
6
18
  include HTTParty
7
19
 
@@ -16,30 +28,68 @@ module Easybill
16
28
  format :json
17
29
 
18
30
  class << self
19
- def authenticate!(api_key)
31
+
32
+ ##
33
+ # Set the authorization header by providing your easybill +api_key+
34
+
35
+ def authenticate(api_key)
20
36
  headers["authorization"] = "Bearer #{api_key}"
21
37
  end
22
38
 
39
+ ##
40
+ # Fetches all resources. You can set custom +query+ parameters.
41
+
23
42
  def list(query: {})
24
43
  get resource_path, query: query
25
44
  end
26
45
 
46
+ ##
47
+ # Fetches a resource by its +id+. You can set custom +query+ parameters.
48
+ # api.find(id, query: {group: 1})
49
+
27
50
  def find(id, query: {})
28
51
  get "#{resource_path}/#{id}", query: query
29
52
  end
30
53
 
54
+ ##
55
+ # Creates a resource. Provide the +data+ as a hash.
56
+ # e.g.
57
+ # data = {
58
+ # first_name: "Lars",
59
+ # last_name: "Bar",
60
+ # ...
61
+ # }
62
+ # api.create(data)
63
+
31
64
  def create(data)
32
65
  post resource_path, body: data.to_json
33
66
  end
34
67
 
68
+ ##
69
+ # Updates a resource. Provide the +id+ and +data+.
70
+ # e.g.
71
+ # id = 123456
72
+ # data = {
73
+ # first_name: "Lars",
74
+ # last_name: "Bar",
75
+ # ...
76
+ # }
77
+ # api.update(id, data)
78
+
35
79
  def update(id, data)
36
80
  put "#{resource_path}/#{id}", body: data.to_json
37
81
  end
38
82
 
83
+ ##
84
+ # Destroys a resource. Provide the +id+.
85
+ # api.destroy(id)
86
+
39
87
  def destroy(id)
40
88
  delete "#{resource_path}/#{id}"
41
89
  end
42
90
 
91
+ protected
92
+
43
93
  def custom(method:, path:, query: {}, data: {}, headers: {})
44
94
  request_options = {}
45
95
 
@@ -60,6 +110,7 @@ module Easybill
60
110
  "#{base_path}/#{dasherize(self.name.split("::").last)}"
61
111
  end
62
112
 
113
+ # TODO-schnika: move this out of here Oo
63
114
  def dasherize(camel_cased_word)
64
115
  camel_cased_word.to_s.gsub(/::/, '/').
65
116
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
@@ -1,58 +1,109 @@
1
1
  module Easybill
2
2
  module Api
3
+
4
+ ##
5
+ # This class represents the client object.
6
+ # Use this class to initialize you api client
7
+
3
8
  class Client
9
+
10
+ ##
11
+ # Create a new client instance with an +api_key+
12
+ #
13
+ # Create or use your generated easybill +api_key+ here
14
+ # @api = Easybill::Api::Client.new("api_key")
15
+
4
16
  def initialize(api_key)
5
- Easybill::Api::Base.authenticate! api_key
17
+ Easybill::Api::Base.authenticate api_key
6
18
  end
7
19
 
20
+ ##
21
+ # Returns a Easybill::Api::Attachments class
22
+
8
23
  def attachments
9
24
  Easybill::Api::Attachments
10
25
  end
11
26
 
27
+ ##
28
+ # Returns a Easybill::Api::Contacts class
29
+
12
30
  def contacts
13
31
  Easybill::Api::Contacts
14
32
  end
15
33
 
34
+ ##
35
+ # Returns a Easybill::Api::CustomerGroups class
36
+
16
37
  def customer_groups
17
38
  Easybill::Api::CustomerGroups
18
39
  end
19
40
 
41
+ ##
42
+ # Returns a Easybill::Api::Customers class
43
+
20
44
  def customers
21
45
  Easybill::Api::Customers
22
46
  end
23
47
 
48
+ ##
49
+ # Returns a Easybill::Api::DocumentPayments class
50
+
24
51
  def document_payments
25
52
  Easybill::Api::DocumentPayments
26
53
  end
27
54
 
55
+ ##
56
+ # Returns a Easybill::Api::Documents class
57
+
28
58
  def documents
29
59
  Easybill::Api::Documents
30
60
  end
31
61
 
62
+ ##
63
+ # Returns a Easybill::Api::PositionGroups class
64
+
32
65
  def position_groups
33
66
  Easybill::Api::PositionGroups
34
67
  end
35
68
 
69
+ ##
70
+ # Returns a Easybill::Api::Positions class
71
+
36
72
  def positions
37
73
  Easybill::Api::Positions
38
74
  end
39
75
 
76
+ ##
77
+ # Returns a Easybill::Api::PostBoxes class
78
+
40
79
  def post_boxes
41
80
  Easybill::Api::PostBoxes
42
81
  end
43
82
 
83
+ ##
84
+ # Returns a Easybill::Api::Projects class
85
+
44
86
  def projects
45
87
  Easybill::Api::Projects
46
88
  end
47
89
 
90
+ ##
91
+ # Returns a Easybill::Api::Tasks class
92
+
48
93
  def tasks
49
94
  Easybill::Api::Tasks
50
95
  end
51
96
 
97
+ ##
98
+ # Returns a Easybill::Api::TextTemplates class
99
+
52
100
  def text_templates
53
101
  Easybill::Api::TextTemplates
54
102
  end
55
103
 
104
+ ##
105
+ # Returns a Easybill::Api::TimeTrackings class
106
+
56
107
  def time_trackings
57
108
  Easybill::Api::TimeTrackings
58
109
  end
@@ -1,5 +1,5 @@
1
1
  module Easybill
2
2
  module Api
3
- VERSION = "0.7.0"
3
+ VERSION = "0.7.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easybill-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Schnetger