debitoor-client 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88c8060b5ab72ad11a6b794f51ea8f811511f4e9
4
- data.tar.gz: f03510606886bb9362abae633c7baa42bce19691
3
+ metadata.gz: 2a351bea09fc141ba0ba7e2b4c92db5050af326a
4
+ data.tar.gz: 2c2a3d59f1f64a2561fdb2368dc2e8ac9476f7c7
5
5
  SHA512:
6
- metadata.gz: 9dda76e5aebfa91f63a2b828309dcc9fdccaeba28acb449ffff3e3a21a5317ec54bc02f884822152d3cb95bf99bea6732a5ae9ef81b71381aa059950bd77c731
7
- data.tar.gz: 2140298a0e7b2bb009bfc066caed979729694f6f0da6c034fd468ea4bac99dfc0bd6867d1afc00c9451a8ac462b61e51e29fc50092ced3d1e3d2a29b67ebd14a
6
+ metadata.gz: 66ca2e90c7de61ac2cfc2f1c9cd9d35488032b8b9430c2a21cf38855d94758c2ad9e296f8fad4f7864f7445c14991af40c8c850e60e33f72aa45eedba7f4baa1
7
+ data.tar.gz: f0f4ce1f7cc1f4bc7f5eaa4795e7f3d7eb725e76f918c3f844f29dbea868bf3a2745853e1c49994f60f3d6eb4a003689da50ad2976c35d8110b7b420d9a0d388
@@ -1,11 +1,11 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'debitoor/client/version'
4
+ require 'debitoor/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "debitoor-client"
8
- spec.version = Debitoor::Client::VERSION
8
+ spec.version = Debitoor::VERSION
9
9
  spec.authors = ["Alessio Santo"]
10
10
  spec.email = ["alessio.santocs@gmail.com"]
11
11
 
@@ -1,4 +1,5 @@
1
- require "debitoor/client/version"
1
+ require "debitoor/version"
2
+ require "httparty"
2
3
 
3
4
  module Debitoor
4
5
  class Client
@@ -7,7 +8,10 @@ module Debitoor
7
8
 
8
9
  def initialize(token)
9
10
  @token = token
10
- @options = { headers: {"x-token" => token} }
11
+ @options = { headers: {
12
+ "x-token" => token,
13
+ "Content-Type" => 'application/json'
14
+ } }
11
15
  end
12
16
 
13
17
  # Public: Creates a draft invoice and accepts a body containing
@@ -27,6 +31,39 @@ module Debitoor
27
31
  }.merge!(@options)
28
32
 
29
33
  response = nil
34
+ id = invoice_id(id_or_response_invoice)
35
+
36
+ response = self.class.post("/api/sales/draftinvoices/#{id}/book/v3", options) if id.present?
37
+ respond_with!(response)
38
+ end
39
+
40
+ def share_invoice(id_or_response_invoice, email, subject="Here's your receipt")
41
+ options = {
42
+ body: {recipient: email, subject: subject}.to_json
43
+ }.merge!(@options)
44
+
45
+ response = nil
46
+ id = invoice_id(id_or_response_invoice)
47
+
48
+ response = self.class.post("/api/sales/invoices/#{id}/share/v1", options) if id.present?
49
+ respond_with!(response)
50
+ end
51
+
52
+ def email_invoice(id_or_response_invoice, email, subject="Here's your receipt", message="")
53
+ options = {
54
+ body: {recipient: email, subject: subject, message: message}.to_json
55
+ }.merge!(@options)
56
+
57
+ response = nil
58
+ id = invoice_id(id_or_response_invoice)
59
+
60
+ response = self.class.post("/api/sales/invoices/#{id}/email/v2", options) if id.present?
61
+ respond_with!(response)
62
+ end
63
+
64
+ private
65
+
66
+ def invoice_id(id_or_response_invoice)
30
67
  id = nil
31
68
  id = id_or_response_invoice if id_or_response_invoice.kind_of?(String)
32
69
 
@@ -34,13 +71,9 @@ module Debitoor
34
71
  id = id_or_response_invoice.parsed_response["id"]
35
72
  end
36
73
 
37
- puts options
38
- response = self.class.post("/api/sales/draftinvoices/#{id}/book/v3", options) if id.present?
39
- respond_with!(response)
74
+ return id
40
75
  end
41
76
 
42
- private
43
-
44
77
  def respond_with!(response)
45
78
  raise(response.inspect) unless response.code.to_s.start_with?("2")
46
79
  return response
@@ -0,0 +1,3 @@
1
+ module Debitoor
2
+ VERSION = "0.1.2"
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debitoor-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessio Santo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-02 00:00:00.000000000 Z
11
+ date: 2019-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -85,7 +85,7 @@ files:
85
85
  - bin/setup
86
86
  - debitoor-client.gemspec
87
87
  - lib/debitoor/client.rb
88
- - lib/debitoor/client/version.rb
88
+ - lib/debitoor/version.rb
89
89
  homepage: https://github.com/milanmaison/debitoor-client
90
90
  licenses:
91
91
  - MIT
@@ -1,5 +0,0 @@
1
- module Debitoor
2
- module Client
3
- VERSION = "0.1.0"
4
- end
5
- end