duedil-client 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 904dd8586926d4f744ba9c4f03896b368ce72000
4
+ data.tar.gz: fd226aa74f641b24ab99280b90f17ab3bbf41725
5
+ SHA512:
6
+ metadata.gz: 22d8f4bf0249ed9a68e3355f8abc839a6b7222e4612d647ce8aacb2f727d249f82a10fa1e3dd4a97231d73ed4eddf04c4878f6c211489af8408ec25ca00734da
7
+ data.tar.gz: e04c0d8392c9dfdfc9f6092a6245ddce94e2dd94e3bc448e81cd2e83efc1c8a3988623524981c2a39e421864ed630e562b66a15d709ab6143bbdcc7a617190f1
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ ruby '2.1.2'
4
+
5
+ # Specify your gem's dependencies in duedil-client.gemspec
6
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Anthony Laibe
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,85 @@
1
+ # Duedil::Client
2
+
3
+ The duedil client provides a simple Ruby interface to the Duedil API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'duedil-client'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install duedil-client
18
+
19
+ ## Usage
20
+
21
+ ### Configuration
22
+
23
+ In order to instantiate the endpoint, a configuration hash is required.
24
+ ```ruby
25
+ config = {
26
+ version: 'v3'
27
+ base_url: 'duedil.io',
28
+ api_key: 'api_key',
29
+ locale: 'uk',
30
+ sandbox: true
31
+ }
32
+ ```
33
+
34
+ ### Company Enpoint
35
+
36
+ ```ruby
37
+ company = Duedil::Company.new config
38
+ ```
39
+
40
+ Available methods:
41
+ ```ruby
42
+ company.all
43
+ company.get(company_id)
44
+ company.registered_address(company_id)
45
+ company.previous_company_names(company_id)
46
+ company.industries(company_id)
47
+ company.shareholders(company_id)
48
+ company.bank_accounts(company_id)
49
+ company.accounts(company_id)
50
+ company.accounts_details(company_id)
51
+ company.documents(company_id)
52
+ company.subsidiaries(company_id)
53
+ company.parent(company_id)
54
+ company.directors(company_id)
55
+ company.directorships(company_id)
56
+ company.mortages(company_id)
57
+ company.service_addresses(company_id)
58
+ ```
59
+
60
+ All the method have an optional argument for filtering (see duedil documentation for more details)
61
+
62
+ ### Director Enpoint
63
+
64
+ ```ruby
65
+ director = Duedil::Director.new config
66
+ ```
67
+
68
+ Available methods:
69
+ ```ruby
70
+ director.all
71
+ director.get(director_id)
72
+ director.companies(director_id)
73
+ director.directorships(director_id)
74
+ director.service_addresses(director_id)
75
+ ```
76
+
77
+ All the method have an optional argument for filtering (see duedil documentation for more details)
78
+
79
+ ## Contributing
80
+
81
+ 1. Fork it ( http://github.com/smartpension/duedil/fork )
82
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
83
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
84
+ 4. Push to the branch (`git push origin my-new-feature`)
85
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'duedil/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "duedil-client"
8
+ spec.version = Duedil::VERSION
9
+ spec.authors = ["Anthony Laibe"]
10
+ spec.email = ["anthony@laibe.cc"]
11
+ spec.summary = %q{The duedil client provides a simple Ruby interface to the Duedil API.}
12
+ spec.description = %q{The duedil client provides a simple Ruby interface to the Duedil API.}
13
+ spec.homepage = "https://github.com/smartpension/duedil-client"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake", "~> 10.4"
23
+ spec.add_development_dependency "rspec", "~> 3.2"
24
+
25
+ spec.add_dependency "activesupport", "~> 4.2"
26
+
27
+ end
@@ -0,0 +1,9 @@
1
+ require 'active_support/all'
2
+
3
+ require 'duedil/version'
4
+ require 'duedil/client'
5
+ require 'duedil/company'
6
+ require 'duedil/director'
7
+
8
+ module Duedil
9
+ end
@@ -0,0 +1,62 @@
1
+ require 'active_support'
2
+ require 'net/http'
3
+ require 'cgi'
4
+
5
+ require 'duedil/response'
6
+
7
+ module Duedil
8
+ module Client
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ attr_accessor :api_key, :version, :base_url, :sandbox, :locale
13
+ end
14
+
15
+ def initialize(options = {})
16
+ @api_key = options.delete(:api_key)
17
+ @version = options.delete(:version)
18
+ @base_url = options.delete(:base_url)
19
+ @sandbox = options.delete(:sandbox).present?
20
+ @locale = options.delete(:locale) || 'uk'
21
+ @http = options.delete(:http) || Net::HTTP
22
+ end
23
+
24
+ private
25
+
26
+ def base_path
27
+ @base_path ||= begin
28
+ path = "/#{version}"
29
+ path += "/sandbox" if sandbox
30
+ path += "/#{locale}"
31
+ path
32
+ end
33
+ end
34
+
35
+ def path(endpoint)
36
+ "#{base_path}/#{endpoint}"
37
+ end
38
+
39
+ def request(path, params = {})
40
+ request_uri = request_uri(path, params.merge(:api_key => api_key))
41
+ response = @http.get_response(base_url, request_uri)
42
+ Response.new(response)
43
+ end
44
+
45
+ def request_uri(path, hash = {})
46
+ query_params = hash.map do |key, value|
47
+ if value.is_a? Hash
48
+ "#{escape(key)}=#{escape(value.to_json)}"
49
+ else
50
+ "#{escape(key)}=#{escape(value)}"
51
+ end
52
+ end
53
+
54
+ path + '?' + query_params.flatten.join('&')
55
+ end
56
+
57
+ def escape(value)
58
+ CGI.escape value.to_s
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,86 @@
1
+ module Duedil
2
+ class Company
3
+ include Duedil::Client
4
+
5
+ def all(filters = {})
6
+ path = path 'companies'
7
+ request path, filters: filters
8
+ end
9
+
10
+ def get(company_id)
11
+ path = path "companies/#{company_id}"
12
+ request path
13
+ end
14
+
15
+ def registered_address(company_id, filters = {})
16
+ path = path "companies/#{company_id}/registered-address"
17
+ request path, filters
18
+ end
19
+
20
+ def previous_company_names(company_id, filters = {})
21
+ path = path "companies/#{company_id}/previous-company-names"
22
+ request path, filters
23
+ end
24
+
25
+ def industries(company_id, filters = {})
26
+ path = path "companies/#{company_id}/industries"
27
+ request path, filters
28
+ end
29
+
30
+ def shareholders(company_id, filters = {})
31
+ path = path "companies/#{company_id}/shareholders"
32
+ request path, filters
33
+ end
34
+
35
+ def bank_accounts(company_id, filters = {})
36
+ path = path "companies/#{company_id}/bank-accounts"
37
+ request path, filters
38
+ end
39
+
40
+ def accounts(company_id, filters = {})
41
+ path = path "companies/#{company_id}/accounts"
42
+ request path, filters
43
+ end
44
+
45
+ def accounts_details(company_id, account_id, filters = {})
46
+ path = path "companies/#{company_id}/accounts/#{account_id}"
47
+ request path, filters
48
+ end
49
+
50
+ def documents(company_id, filters = {})
51
+ path = path "companies/#{company_id}/documents"
52
+ request path, filters
53
+ end
54
+
55
+ def subsidiaries(company_id, filters = {})
56
+ path = path "companies/#{company_id}/subsidiaries"
57
+ request path, filters
58
+ end
59
+
60
+ def parent(company_id, filters = {})
61
+ path = path "companies/#{company_id}/parent"
62
+ request path, filters
63
+ end
64
+
65
+ def directors(company_id, filters = {})
66
+ path = path "companies/#{company_id}/directors"
67
+ request path, filters
68
+ end
69
+
70
+ def directorships(company_id, filters = {})
71
+ path = path "companies/#{company_id}/directorships"
72
+ request path, filters
73
+ end
74
+
75
+ def mortages(company_id, filters = {})
76
+ path = path "companies/#{company_id}/mortages"
77
+ request path, filters
78
+ end
79
+
80
+ def service_addresses(company_id, filters = {})
81
+ path = path "companies/#{company_id}/service-addresses"
82
+ request path, filters
83
+ end
84
+
85
+ end
86
+ end
@@ -0,0 +1,31 @@
1
+ module Duedil
2
+ class Director
3
+ include Duedil::Client
4
+
5
+ def all(filters = {})
6
+ path = path 'directors'
7
+ request path, filters: filters
8
+ end
9
+
10
+ def get(director_id)
11
+ path = path "directors/#{director_id}"
12
+ request path
13
+ end
14
+
15
+ def companies(director_id, filters = {})
16
+ path = path "directors/#{director_id}/companies"
17
+ request path, filters
18
+ end
19
+
20
+ def directorships(director_id, filters = {})
21
+ path = path "directors/#{director_id}/directorships"
22
+ request path, filters
23
+ end
24
+
25
+ def service_addresses(director_id, filters = {})
26
+ path = path "directors/#{director_id}/service-addresses"
27
+ request path, filters
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,38 @@
1
+ require 'json'
2
+ require 'duedil/struct'
3
+
4
+ module Duedil
5
+ class Response
6
+ def initialize(http_response)
7
+ @http_response = http_response
8
+ end
9
+
10
+ def respond_to_missing?(name, include_private = false)
11
+ @http_response.respond_to?(name)
12
+ end
13
+
14
+ def method_missing(name, *args, &block)
15
+ @http_response.send(name, *args, &block)
16
+ end
17
+
18
+ def ok?
19
+ code.to_i == 200
20
+ end
21
+
22
+ def hash
23
+ object.hash
24
+ end
25
+
26
+ def list
27
+ hash['data'].map(&:hash) if hash['data'].present?
28
+ end
29
+
30
+ def json?
31
+ self['Content-Type'].split(';').first == 'application/json'
32
+ end
33
+
34
+ def object
35
+ @object ||= JSON.parse(body, :object_class => Struct).response
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,32 @@
1
+ module Duedil
2
+ class Struct
3
+ attr_reader :hash
4
+
5
+ def initialize
6
+ @hash = {}
7
+ end
8
+
9
+ def [](key)
10
+ @hash[key]
11
+ end
12
+
13
+ def []=(key, value)
14
+ @hash[key] = value
15
+ end
16
+
17
+ def method_missing(name, *args, &block)
18
+ key = name.to_s.gsub(/_(\w)/) { $1.capitalize }
19
+
20
+ if @hash.has_key?(key) && args.empty? && block.nil?
21
+ @hash[key]
22
+ else
23
+ super name, *args, &block
24
+ end
25
+ end
26
+
27
+ def respond_to_missing?(name, include_private = false)
28
+ @hash.has_key?(name.to_s.gsub(/_(\w)/) { $1.capitalize })
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module Duedil
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+ require 'duedil'
3
+
4
+ describe Duedil::Company do
5
+ before do
6
+ @api_key = 'exampleapikey'
7
+ @base_url = 'duedil'
8
+ @version = 'v'
9
+ @http = double('http')
10
+ @client = Duedil::Company.new version: @version,
11
+ base_url: @base_url,
12
+ api_key: 'test',
13
+ sandbox: 'true',
14
+ http: @http
15
+ end
16
+
17
+ describe '#all' do
18
+ it 'build the correct url for searching companies' do
19
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/companies?filters=%7B%22name%22%3A%22foo%22%7D&api_key=test")
20
+ @client.all(name: 'foo')
21
+ end
22
+ end
23
+
24
+ describe '#get' do
25
+ it 'build the correct url for fetching a company' do
26
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/companies/1?api_key=test")
27
+ @client.get(1)
28
+ end
29
+ end
30
+
31
+ describe '#registered_address' do
32
+ it 'build the correct url for fetching registered_address' do
33
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/companies/1/registered-address?limit=100&api_key=test")
34
+ @client.registered_address(1, limit: 100)
35
+ end
36
+ end
37
+
38
+ describe '#previous_company_names' do
39
+ it 'build the correct url for fetching previous_company_names' do
40
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/companies/1/previous-company-names?limit=100&api_key=test")
41
+ @client.previous_company_names(1, limit: 100)
42
+ end
43
+ end
44
+
45
+ describe '#industries' do
46
+ it 'build the correct url for fetching industries' do
47
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/companies/1/industries?limit=100&api_key=test")
48
+ @client.industries(1, limit: 100)
49
+ end
50
+ end
51
+
52
+ describe '#shareholders' do
53
+ it 'build the correct url for fetching shareholders' do
54
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/companies/1/shareholders?limit=100&api_key=test")
55
+ @client.shareholders(1, limit: 100)
56
+ end
57
+ end
58
+
59
+ describe '#bank_accounts' do
60
+ it 'build the correct url for fetching bank_accounts' do
61
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/companies/1/bank-accounts?limit=100&api_key=test")
62
+ @client.bank_accounts(1, limit: 100)
63
+ end
64
+ end
65
+
66
+ describe '#accounts' do
67
+ it 'build the correct url for fetching accounts' do
68
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/companies/1/accounts?limit=100&api_key=test")
69
+ @client.accounts(1, limit: 100)
70
+ end
71
+ end
72
+
73
+ describe '#accounts_details' do
74
+ it 'build the correct url for fetching accounts_details' do
75
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/companies/1/accounts/1?limit=100&api_key=test")
76
+ @client.accounts_details(1, 1, limit: 100)
77
+ end
78
+ end
79
+
80
+ describe '#documents' do
81
+ it 'build the correct url for fetching documents' do
82
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/companies/1/documents?limit=100&api_key=test")
83
+ @client.documents(1, limit: 100)
84
+ end
85
+ end
86
+
87
+ describe '#subsidiaries' do
88
+ it 'build the correct url for fetching subsidiaries' do
89
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/companies/1/subsidiaries?limit=100&api_key=test")
90
+ @client.subsidiaries(1, limit: 100)
91
+ end
92
+ end
93
+
94
+ describe '#parent' do
95
+ it 'build the correct url for fetching parent' do
96
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/companies/1/parent?limit=100&api_key=test")
97
+ @client.parent(1, limit: 100)
98
+ end
99
+ end
100
+
101
+ describe '#directors' do
102
+ it 'build the correct url for fetching directors' do
103
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/companies/1/directors?limit=100&api_key=test")
104
+ @client.directors(1, limit: 100)
105
+ end
106
+ end
107
+
108
+ describe '#directorships' do
109
+ it 'build the correct url for fetching directorships' do
110
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/companies/1/directorships?limit=100&api_key=test")
111
+ @client.directorships(1, limit: 100)
112
+ end
113
+ end
114
+
115
+ describe '#mortages' do
116
+ it 'build the correct url for fetching mortages' do
117
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/companies/1/mortages?limit=100&api_key=test")
118
+ @client.mortages(1, limit: 100)
119
+ end
120
+ end
121
+
122
+ describe '#service_addresses' do
123
+ it 'build the correct url for fetching service_addresses' do
124
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/companies/1/service-addresses?limit=100&api_key=test")
125
+ @client.service_addresses(1, limit: 100)
126
+ end
127
+ end
128
+
129
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+ require 'duedil'
3
+
4
+ describe Duedil::Director do
5
+ before do
6
+ @api_key = 'exampleapikey'
7
+ @base_url = 'duedil'
8
+ @version = 'v'
9
+ @http = double('http')
10
+ @client = Duedil::Director.new version: @version,
11
+ base_url: @base_url,
12
+ api_key: 'test',
13
+ sandbox: 'true',
14
+ http: @http
15
+ end
16
+
17
+ describe '#all' do
18
+ it 'build the correct url for searching companies' do
19
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/directors?filters=%7B%22name%22%3A%22foo%22%7D&api_key=test")
20
+ @client.all(name: 'foo')
21
+ end
22
+ end
23
+
24
+ describe '#get' do
25
+ it 'build the correct url for fetching a company' do
26
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/directors/1?api_key=test")
27
+ @client.get(1)
28
+ end
29
+ end
30
+
31
+ describe '#companies' do
32
+ it 'build the correct url for fetching registered_address' do
33
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/directors/1/companies?limit=100&api_key=test")
34
+ @client.companies(1, limit: 100)
35
+ end
36
+ end
37
+
38
+ describe '#directorships' do
39
+ it 'build the correct url for fetching previous_company_names' do
40
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/directors/1/directorships?limit=100&api_key=test")
41
+ @client.directorships(1, limit: 100)
42
+ end
43
+ end
44
+
45
+ describe '#service_addresses' do
46
+ it 'build the correct url for fetching industries' do
47
+ allow(@http).to receive(:get_response).with(@base_url, "/v/sandbox/uk/directors/1/service-addresses?limit=100&api_key=test")
48
+ @client.service_addresses(1, limit: 100)
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+ require 'duedil/response'
4
+
5
+ describe Duedil::Response do
6
+ before do
7
+ @http_response = double
8
+
9
+ @response = Duedil::Response.new(@http_response)
10
+ end
11
+
12
+ it 'delegates missing methods to the http response object' do
13
+ allow(@http_response).to receive(:code).and_return('200')
14
+
15
+ expect(@response.code).to be_eql '200'
16
+ end
17
+
18
+ describe 'ok query method' do
19
+ it 'returns true if the status code is 200' do
20
+ allow(@http_response).to receive(:code).and_return('200')
21
+
22
+ expect(@response.ok?).to be_eql true
23
+ end
24
+
25
+ it 'returns false otherwise' do
26
+ allow(@http_response).to receive(:code).and_return('400')
27
+
28
+ expect(@response.ok?).to be_eql false
29
+ end
30
+ end
31
+
32
+ describe 'json query method' do
33
+ it 'returns true if the response has a json content type' do
34
+ allow(@http_response).to receive(:[]).with('Content-Type').and_return('application/json;charset=utf-8')
35
+
36
+ expect(@response.json?).to be_eql true
37
+ end
38
+
39
+ it 'returns false otherwise' do
40
+ allow(@http_response).to receive(:[]).with('Content-Type').and_return('text/html')
41
+
42
+ expect(@response.json?).to be_eql false
43
+ end
44
+ end
45
+
46
+ describe 'object method' do
47
+ it 'decodes the response body as json and returns a struct object' do
48
+ allow(@http_response).to receive(:body).and_return('{"response":{"foo":"bar"}}')
49
+
50
+ expect(@response.object).to be_instance_of Duedil::Struct
51
+ end
52
+ end
53
+
54
+ describe 'hash method' do
55
+ it 'delegates hash to object' do
56
+ allow(@http_response).to receive(:body).and_return('{"response":{"foo":"bar"}}')
57
+
58
+ expect(@response.hash).to be_eql @response.object.hash
59
+ end
60
+ end
61
+
62
+ describe 'list method' do
63
+ context 'when the hash has data' do
64
+ it 'should return data hash' do
65
+ allow(@http_response).to receive(:body).and_return('{"response":{"data":[{"foo":"bar"}]}}')
66
+
67
+ expect(@response.list).to be_eql [{"foo" => "bar"}]
68
+ end
69
+ end
70
+
71
+ context 'when the hash does not have data' do
72
+ it 'should return nil' do
73
+ allow(@http_response).to receive(:body).and_return('{"response":{"foo":"bar"}}')
74
+
75
+ expect(@response.list).to be_nil
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+ require 'duedil/struct'
4
+
5
+ describe Duedil::Struct do
6
+ it 'can be used as a json object class' do
7
+ struct = JSON.parse('{}', :object_class => Duedil::Struct)
8
+ expect(struct).to be_instance_of Duedil::Struct
9
+ end
10
+
11
+ it 'provides snakecase reader methods for the json object members' do
12
+ struct = JSON.parse('{"latestAnnualReturnDate":"2012-04-20"}', :object_class => Duedil::Struct)
13
+ expect(struct.latest_annual_return_date).to be_eql '2012-04-20'
14
+ end
15
+
16
+ it 'responds to snakecase reader methods for the json object members' do
17
+ struct = JSON.parse('{"latestAnnualReturnDate":"2012-04-20"}', :object_class => Duedil::Struct)
18
+ expect(struct.respond_to?(:latest_annual_return_date)).to be_eql true
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ require 'rspec'
2
+
3
+ RSpec.configure do |c|
4
+ c.mock_with :rspec
5
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: duedil-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Anthony Laibe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.2'
69
+ description: The duedil client provides a simple Ruby interface to the Duedil API.
70
+ email:
71
+ - anthony@laibe.cc
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - duedil_client.gemspec
82
+ - lib/duedil.rb
83
+ - lib/duedil/client.rb
84
+ - lib/duedil/company.rb
85
+ - lib/duedil/director.rb
86
+ - lib/duedil/response.rb
87
+ - lib/duedil/struct.rb
88
+ - lib/duedil/version.rb
89
+ - spec/duedil/company_spec.rb
90
+ - spec/duedil/director_spec.rb
91
+ - spec/duedil/response_spec.rb
92
+ - spec/duedil/struct_spec.rb
93
+ - spec/spec_helper.rb
94
+ homepage: https://github.com/smartpension/duedil-client
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.2.2
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: The duedil client provides a simple Ruby interface to the Duedil API.
118
+ test_files:
119
+ - spec/duedil/company_spec.rb
120
+ - spec/duedil/director_spec.rb
121
+ - spec/duedil/response_spec.rb
122
+ - spec/duedil/struct_spec.rb
123
+ - spec/spec_helper.rb