freemle 1.0.0 → 1.0.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: 4e1013fba2d5336932c0827e8d014bce165a24f3
4
- data.tar.gz: 79bfd250d6e893121d107ca72ca496e6ed1dfd1c
3
+ metadata.gz: c8d1398668ee673aa3e885194ced4026c9472c61
4
+ data.tar.gz: b08a0aaf67a699b12ebda89854e21cfc80963bb5
5
5
  SHA512:
6
- metadata.gz: 04ff928ebaff86b4ebad56f803f761389c484fb0a6b4ca977c2c48f0bfb26a042fdbd28519be66281becea281b94dc22340ca1f5d8379a48d712070b34b58966
7
- data.tar.gz: 45427f788741f31dd3bd32dcade47882a853a2bb0b5740d27161ad92e4e644415dceafbc10229e76dc243414ea7c839bfe71dbab28987d8620c62440585c1691
6
+ metadata.gz: bc3db1cf169ede87cc73b975e284280709d1fa8de29f6b049aadcc2cb1e52547ae66265fb262b69dcd9f02933371598fcd975e9a3cde134aceb1736b4a7e04c5
7
+ data.tar.gz: b835d9a78081dc6350297cfbff9a43742deb42c5ad534a9c477e4accc8d859e49d8fa85a3d23c4a608e76e8fd92a321b5f67ef97a47b6ab5efcf4866eafbb133
data/README.md CHANGED
@@ -10,7 +10,7 @@ A Ruby interface to the [Freemle](https://www.freemle.com/) REST API.
10
10
 
11
11
  To create a freemle client:
12
12
  ```ruby
13
- freemle = Freemle::Client.new(
13
+ freemle = Freemle.client(
14
14
  app_name: "application-name-as-chosen-on-freemle.com",
15
15
  api_key: "api-key-as-provided-by-freemle.com"
16
16
  )
@@ -18,9 +18,8 @@ freemle = Freemle::Client.new(
18
18
 
19
19
  ### Customers
20
20
 
21
- Accessing customers:
21
+ Accessing customers (`freemle.customers.search('Freemle')`) returns:
22
22
  ```ruby
23
- freemle.customers.search('Freemle')
24
23
  [{
25
24
  company_name: 'Freemle',
26
25
  address: {
@@ -40,8 +39,10 @@ freemle.customers.search('Freemle')
40
39
 
41
40
  Adding customers:
42
41
  ```ruby
43
- customers.create(
42
+ freemle.customers.create(
44
43
  company_name: "Zilverline B.V.",
44
+ attn: "Vibiemme", # Optional
45
+ extra_information: "The best cofee maker!", # Optional
45
46
  address: {
46
47
  street: "Cruquiusweg 109 F",
47
48
  postal_code: "1019 AG",
@@ -55,10 +56,16 @@ customers.create(
55
56
 
56
57
  Adding invoices:
57
58
  ```ruby
58
- invoices.create(
59
- customer_id: "123456789",
59
+ freemle.invoices.create(
60
+ customer_id: "123456789", # Optional
61
+ delivery_period: "31-12-1234", # Optional
62
+ reference: "my-reference", # Optional
63
+ line_items: [
64
+ {vat: 21, amount: 1359.50, quantity: 1, description: "Scrum Training"}
65
+ ]
60
66
  )
61
67
  ```
68
+
62
69
  ## Documentation
63
70
 
64
71
  Check https://www.freemle.com/api-documentatie for more info.
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Freemle::Client::VERSION
9
9
  spec.authors = ['Bob Forma', 'Steven Weller']
10
10
  spec.email = %w(bforma@zilverline.com suweller@zilverline.com)
11
- spec.summary = %w(Freemle.com REST API client)
11
+ spec.summary = 'Freemle.com REST API client'
12
12
  spec.homepage = 'https://www.freemle.com/api-documentatie'
13
13
  spec.license = 'MIT'
14
14
 
@@ -19,9 +19,9 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_runtime_dependency 'rest-client', '~> 1.6'
21
21
 
22
- spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'bundler', '~> 1.0'
23
23
  spec.add_development_dependency 'coveralls', '~> 0.7'
24
- spec.add_development_dependency 'rake', '~> 10.3'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
25
  spec.add_development_dependency 'rspec', '~> 2.14'
26
26
  spec.add_development_dependency 'webmock', '~> 1.17'
27
27
  end
data/lib/freemle.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'freemle/client'
2
+ require 'freemle/client/version'
3
+
4
+ module Freemle
5
+
6
+ # Convenient way to initialize a freemle client.
7
+ #
8
+ # @see {Freemle::Client.initialize}
9
+ #
10
+ # @since 1.0.1
11
+ def client(*args)
12
+ Freemle::Client.new(*args)
13
+ end
14
+ module_function :client
15
+
16
+ end
@@ -1,9 +1,9 @@
1
- require "freemle/client/version"
2
- require "freemle/resource"
1
+ require 'freemle/client/resource'
3
2
 
4
3
  module Freemle
4
+
5
5
  class Client
6
- BASE_URL = "https://www.freemle.com/api"
6
+ BASE_URL = 'https://www.freemle.com/api'
7
7
 
8
8
  attr_accessor :base_url, :app_name, :api_key
9
9
 
@@ -32,11 +32,11 @@ module Freemle
32
32
  # @example
33
33
  # client.customers
34
34
  #
35
- # @return [ Freemle::Resource ] entry to the customer resource.
35
+ # @return [ Freemle::Client::Resource ] entry to the customer resource.
36
36
  #
37
37
  # @since 1.0.0
38
38
  def customers
39
- @customers ||= Freemle::Resource.new(self, :customer, :customers)
39
+ @customers ||= new_resource(self, :customer, :customers)
40
40
  end
41
41
 
42
42
  # Access the invoice resource.
@@ -44,11 +44,22 @@ module Freemle
44
44
  # @example
45
45
  # client.invoices
46
46
  #
47
- # @return [ Freemle::Resource ] entry to the invoice resource.
47
+ # @return [ Freemle::Client::Resource ] entry to the invoice resource.
48
48
  #
49
49
  # @since 1.0.0
50
50
  def invoices
51
- @invoices ||= Freemle::Resource.new(self, :invoice, :invoices)
51
+ @invoices ||= new_resource(self, :invoice, :invoices)
52
+ end
53
+
54
+ private
55
+
56
+ # Creates a freemle client resource based on the passed configuration
57
+ #
58
+ # @return [ Freemle::Client::Resource ] entry to a resource.
59
+ #
60
+ # @since 1.0.1
61
+ def new_resource(*args)
62
+ Freemle::Client::Resource.new(*args)
52
63
  end
53
64
 
54
65
  end
@@ -0,0 +1,102 @@
1
+ require 'rest-client'
2
+
3
+ module Freemle
4
+ class Client
5
+ class Resource < Struct.new(:config, :singular, :plural)
6
+
7
+ # Performs a search on this resource, given a query.
8
+ #
9
+ # @example
10
+ # customers.search('Zilverline')
11
+ #
12
+ # @example
13
+ # customers.search('Zilverline') do |response|
14
+ # # Roll your own response handler
15
+ # end
16
+ #
17
+ # @param [ Hash ] query A hash containing the fields to search for.
18
+ # @param [ Proc ] block A custom response handler.
19
+ #
20
+ # @return [ Array<Hash> ] By default, a JSON parsed response body.
21
+ #
22
+ # @since 1.0.0
23
+ def search(query, &block)
24
+ block = default_handler unless block_given?
25
+ request.get(params: {query: query}, &block)
26
+ end
27
+
28
+ # Persists a resource on freemle.com, given a payload.
29
+ #
30
+ # @example
31
+ # customers.create(
32
+ # company_name: "Zilverline B.V.",
33
+ # address: {
34
+ # street: "Cruquiusweg 109 F",
35
+ # postal_code: "1019 AG",
36
+ # city: "Amsterdam",
37
+ # country_code: "NL"
38
+ # }
39
+ # )
40
+ #
41
+ # @example
42
+ # customers.create(
43
+ # company_name: "Zilverline B.V.",
44
+ # address: {
45
+ # street: "Cruquiusweg 109 F",
46
+ # postal_code: "1019 AG",
47
+ # city: "Amsterdam",
48
+ # country_code: "NL"
49
+ # }
50
+ # ) do |response|
51
+ # # Roll your own response handler
52
+ # end
53
+ #
54
+ # @param [ Hash ] payload A hash containing the fields to set.
55
+ # @param [ Proc ] block A custom response handler.
56
+ #
57
+ # @return [ Hash ] By default, a JSON parsed response body.
58
+ #
59
+ # @since 1.0.0
60
+ def create(payload, &block)
61
+ block = default_handler unless block_given?
62
+ request.post(json.generate({singular => payload}), &block)
63
+ end
64
+
65
+ private
66
+
67
+ # Returns a response handler, which parses the response body as JSON.
68
+ #
69
+ # @return [ Proc ] Default response handler.
70
+ #
71
+ # @since 1.0.0
72
+ def default_handler
73
+ Proc.new { |response| json.parse(response.body) }
74
+ end
75
+
76
+ # Returns a new request handler for this resource.
77
+ #
78
+ # @return [ RestClient::Resource ] A request handler.
79
+ #
80
+ # @since 1.0.0
81
+ def request
82
+ RestClient::Resource.new(
83
+ "#{config.base_url}/#{plural}",
84
+ user: config.app_name,
85
+ password: config.api_key
86
+ )
87
+ end
88
+
89
+ # Returns the JSON library used in request and default response handling.
90
+ #
91
+ # @return [ Class ] A JSON library.
92
+ #
93
+ # @since 1.0.0
94
+ def json
95
+ return @json if @json
96
+ require 'json'
97
+ @json = JSON
98
+ end
99
+
100
+ end
101
+ end
102
+ end
@@ -1,5 +1,5 @@
1
1
  module Freemle
2
2
  class Client
3
- VERSION = "1.0.0"
3
+ VERSION = '1.0.1'
4
4
  end
5
5
  end
@@ -29,7 +29,7 @@ describe Freemle::Client do
29
29
  describe "#customers" do
30
30
  subject { client.customers }
31
31
 
32
- it { should be_instance_of(Freemle::Resource) }
32
+ it { should be_instance_of(Freemle::Client::Resource) }
33
33
  its(:singular) { should eq(:customer) }
34
34
  its(:plural) { should eq(:customers) }
35
35
  end
@@ -37,7 +37,7 @@ describe Freemle::Client do
37
37
  describe "#invoices" do
38
38
  subject { client.invoices }
39
39
 
40
- it { should be_instance_of(Freemle::Resource) }
40
+ it { should be_instance_of(Freemle::Client::Resource) }
41
41
  its(:singular) { should eq(:invoice) }
42
42
  its(:plural) { should eq(:invoices) }
43
43
  end
@@ -1,10 +1,10 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Freemle::Resource do
3
+ describe Freemle::Client::Resource do
4
4
  let(:client) do
5
5
  double("client", base_url: "foo", app_name: "app", api_key: "secret")
6
6
  end
7
- let(:resource) { Freemle::Resource.new(client, :customer, :customers) }
7
+ let(:resource) { Freemle::Client::Resource.new(client, :customer, :customers) }
8
8
 
9
9
  describe "#search" do
10
10
  subject { resource.search("terms") }
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Freemle do
4
+ describe '.client' do
5
+ subject { Freemle.client(app_name: 'name', api_key: 'secret') }
6
+ it { should be_instance_of(Freemle::Client) }
7
+ end
8
+ end
data/spec/spec_helper.rb CHANGED
@@ -8,7 +8,7 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
8
  SimpleCov.start
9
9
  # Coveralls.wear!
10
10
 
11
- require "rspec"
12
- require "webmock/rspec"
11
+ require 'rspec'
12
+ require 'webmock/rspec'
13
13
 
14
- require "freemle/client"
14
+ require 'freemle'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freemle
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Forma
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '1.6'
34
+ version: '1.0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '1.6'
41
+ version: '1.0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: coveralls
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -59,14 +59,14 @@ dependencies:
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '10.3'
62
+ version: '10.0'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '10.3'
69
+ version: '10.0'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rspec
72
72
  requirement: !ruby/object:Gem::Requirement
@@ -111,11 +111,13 @@ files:
111
111
  - README.md
112
112
  - Rakefile
113
113
  - freemle-client.gemspec
114
+ - lib/freemle.rb
114
115
  - lib/freemle/client.rb
116
+ - lib/freemle/client/resource.rb
115
117
  - lib/freemle/client/version.rb
116
- - lib/freemle/resource.rb
117
118
  - spec/freemle/client_spec.rb
118
119
  - spec/freemle/resource_spec.rb
120
+ - spec/freemle_spec.rb
119
121
  - spec/spec_helper.rb
120
122
  homepage: https://www.freemle.com/api-documentatie
121
123
  licenses:
@@ -140,8 +142,9 @@ rubyforge_project:
140
142
  rubygems_version: 2.2.0
141
143
  signing_key:
142
144
  specification_version: 4
143
- summary: "[\"Freemle.com\", \"REST\", \"API\", \"client\"]"
145
+ summary: Freemle.com REST API client
144
146
  test_files:
145
147
  - spec/freemle/client_spec.rb
146
148
  - spec/freemle/resource_spec.rb
149
+ - spec/freemle_spec.rb
147
150
  - spec/spec_helper.rb
@@ -1,100 +0,0 @@
1
- require 'rest-client'
2
-
3
- module Freemle
4
- class Resource < Struct.new(:config, :singular, :plural)
5
-
6
- # Performs a search on this resource, given a query.
7
- #
8
- # @example
9
- # customers.search('Zilverline')
10
- #
11
- # @example
12
- # customers.search('Zilverline') do |response|
13
- # # Roll your own response handler
14
- # end
15
- #
16
- # @param [ Hash ] query A hash containing the fields to search for.
17
- # @param [ Proc ] block A custom response handler.
18
- #
19
- # @return [ Array<Hash> ] By default, a JSON parsed response body.
20
- #
21
- # @since 1.0.0
22
- def search(query, &block)
23
- block = default_handler unless block_given?
24
- request.get(params: {query: query}, &block)
25
- end
26
-
27
- # Persists a resource on freemle.com, given a payload.
28
- #
29
- # @example
30
- # customers.create(
31
- # company_name: "Zilverline B.V.",
32
- # address: {
33
- # street: "Cruquiusweg 109 F",
34
- # postal_code: "1019 AG",
35
- # city: "Amsterdam",
36
- # country_code: "NL"
37
- # }
38
- # )
39
- #
40
- # @example
41
- # customers.create(
42
- # company_name: "Zilverline B.V.",
43
- # address: {
44
- # street: "Cruquiusweg 109 F",
45
- # postal_code: "1019 AG",
46
- # city: "Amsterdam",
47
- # country_code: "NL"
48
- # }
49
- # ) do |response|
50
- # # Roll your own response handler
51
- # end
52
- #
53
- # @param [ Hash ] payload A hash containing the fields to set.
54
- # @param [ Proc ] block A custom response handler.
55
- #
56
- # @return [ Hash ] By default, a JSON parsed response body.
57
- #
58
- # @since 1.0.0
59
- def create(payload, &block)
60
- block = default_handler unless block_given?
61
- request.post(json.generate({singular => payload}), &block)
62
- end
63
-
64
- private
65
-
66
- # Returns a response handler, which parses the response body as JSON.
67
- #
68
- # @return [ Proc ] Default response handler.
69
- #
70
- # @since 1.0.0
71
- def default_handler
72
- Proc.new { |response| json.parse(response.body) }
73
- end
74
-
75
- # Returns a new request handler for this resource.
76
- #
77
- # @return [ RestClient::Resource ] A request handler.
78
- #
79
- # @since 1.0.0
80
- def request
81
- RestClient::Resource.new(
82
- "#{config.base_url}/#{plural}",
83
- user: config.app_name,
84
- password: config.api_key
85
- )
86
- end
87
-
88
- # Returns the JSON library used in request and default response handling.
89
- #
90
- # @return [ Class ] A JSON library.
91
- #
92
- # @since 1.0.0
93
- def json
94
- return @json if @json
95
- require 'json'
96
- @json = JSON
97
- end
98
-
99
- end
100
- end