companies_house_client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 50896e2d1da28f734cbd6c8a6cbae9859ab196db
4
+ data.tar.gz: b8f80f042bf138cdc979bef786fff4b10d1f7352
5
+ SHA512:
6
+ metadata.gz: 92d4f8a1d54a754e296d156891a5048c386ee3236687b59273b6f223635de0164e4227c876a8579bdd0540426eedc3f9d2133a938b5225bd08d6ba39d56b6b49
7
+ data.tar.gz: 303c9aa305fd9bdd6d8092cf717a686882e9534353fd242a2497ea9e098221c0c581b29a1ba6477dc96a835569a178d095511b56b92866120b1efc1a20d43641
data/.gitignore ADDED
@@ -0,0 +1,23 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ companies_house_client
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in companies_house_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Error Ltd.
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.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # CompaniesHouseClient
2
+ A wrapper around the [Companies House Rest API](https://developer.companieshouse.gov.uk/api/docs/).
3
+
4
+ There is another gem which does this, [open-companies-house](https://github.com/tomblomfield/open-companies-house) but it doesn't include authentication.
5
+
6
+ ## Installation
7
+
8
+ Install with [Bundler](http://bundler.io) like this:
9
+
10
+ ```
11
+ gem 'companies_house_client'
12
+ ```
13
+
14
+ Or manually:
15
+
16
+ ```
17
+ gem install companies_house_client
18
+ ```
19
+
20
+ ## Setup
21
+
22
+ Set up CompaniesHouseClient in a block:
23
+
24
+ ```
25
+ CompaniesHouseClient.configure do |config|
26
+ config.api_token #your token from https://developer.companieshouse.gov.uk/developer/applications
27
+ config.ssl_settings #this gem uses Faraday; you need to point it at the appropriate CA bundle for your platform
28
+ end
29
+
30
+ ```
31
+
32
+ ### SSL Setup
33
+ SSL is a bit of a faff, because you need a [CA bundle for Faraday](https://github.com/lostisland/faraday/wiki/Setting-up-SSL-certificates).
34
+
35
+ The configuration setting `ssl_settings` is a hash. You need to pass `ca_path` into it, with the appropriate location for your bundle.
36
+
37
+ ## Use
38
+
39
+ ### Getting a company by Company Number
40
+ Note that the leading zero in a company number is important so you have to pass `find()` a string.
41
+ ```
42
+ c = CompaniesHouseClient::Company.find("company number")
43
+ c #returns a company.
44
+ ```
45
+
46
+ ### Searching for a company by name
47
+ You can search for a company like this:
48
+
49
+ ```
50
+ companies = CompaniesHouseClient::Company.search("your search", per_page: 10, page: 2)
51
+ companies #returns a collection of Companies which match your search.
52
+ ```
53
+
54
+ `per_page` and `page` are optional.
55
+
56
+ ### Company Officers
57
+ Companies have many officers. You can retrieve them like this:
58
+
59
+ ```
60
+ c = CompaniesHouseClient::Company.find("company number")
61
+ c.officers #returns a collection of Officer objects.
62
+ ```
63
+
64
+
65
+ ## To do
66
+
67
+ * We should be able to get a history of accounts.
68
+
69
+ # Licence
70
+ This gem is MIT licenced. Have fun!
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -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 'companies_house_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "companies_house_client"
8
+ spec.version = CompaniesHouseClient::VERSION
9
+ spec.authors = ["Ed Jones"]
10
+ spec.email = ["ed@errorstudio.co.uk"]
11
+ spec.summary = %q{A REST client for the UK Companies House API}
12
+ spec.description = %q{A REST client for the UK Companies House API, including authentication}
13
+ spec.homepage = "https://github.com/errorstudio/companies_house_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.6"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "require_all"
25
+ spec.add_dependency "her"
26
+
27
+ end
@@ -0,0 +1,53 @@
1
+ require 'require_all'
2
+ require 'her'
3
+ require_rel "."
4
+
5
+
6
+ module CompaniesHouseClient
7
+ API_URL = "https://api.companieshouse.gov.uk"
8
+ class << self
9
+
10
+ #access the configuration class
11
+ attr_accessor :configuration
12
+
13
+ #block for configuration.
14
+ def configure
15
+ self.configuration ||= Configuration.new
16
+ yield(configuration)
17
+ self.configuration.configure_connection
18
+ end
19
+ end
20
+
21
+ class Configuration
22
+ attr_accessor :api_key, :url, :ssl_options, :proxy
23
+ attr_reader :connection
24
+
25
+ def initialize
26
+ @connection ||= Her::API.new
27
+ @api_key = ""
28
+ @url = CompaniesHouseClient::API_URL
29
+ @ssl_options = {
30
+ ca_path: CompaniesHouseClient::CAPath.platform_path
31
+ }
32
+ @proxy
33
+ end
34
+
35
+ def configure_connection
36
+
37
+ @connection.setup url: @url, ssl: @ssl_options, proxy: @proxy do |c|
38
+
39
+ #Auth
40
+ c.use Faraday::Request::BasicAuthentication, @api_key, ''
41
+
42
+ # Request
43
+ c.use Faraday::Request::UrlEncoded
44
+
45
+ # Parse collections
46
+ c.use CompaniesHouseClient::CollectionParser
47
+
48
+ # Adapter
49
+ c.use Faraday::Adapter::NetHttp
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,6 @@
1
+ module CompaniesHouseClient
2
+ class Base
3
+ include Her::Model
4
+ use_api -> {CompaniesHouseClient.configuration.connection}
5
+ end
6
+ end
@@ -0,0 +1,15 @@
1
+ require 'rbconfig'
2
+ module CompaniesHouseClient
3
+ class CAPath
4
+ class << self
5
+ def platform_path
6
+ case RbConfig::CONFIG['host_os']
7
+ when /linux|arch/i
8
+ "/usr/lib/ssl"
9
+ when /darwin/i
10
+ "/System/Library/OpenSSL"
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module CompaniesHouseClient
2
+
3
+ # Clean up collections, which look like this:
4
+ # {
5
+ # "total_results": 4,
6
+ # "items": [
7
+ # { }, #some item
8
+ # { }, #some item
9
+ # ]
10
+ # }
11
+ class CollectionParser < Faraday::Response::Middleware
12
+ def on_complete(env)
13
+ json = MultiJson.load(env[:body], symbolize_keys: true)
14
+ env[:body] = {
15
+ data: json.has_key?(:items) ? json[:items] : json
16
+ }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ module CompaniesHouseClient
2
+ class Company < Base
3
+ has_many :officers
4
+ collection_path "/company"
5
+ primary_key :company_number
6
+
7
+ def self.search(term, per_page: nil, start: nil)
8
+ get("/search",{q: term, items_per_page: per_page, start_index: start})
9
+ end
10
+
11
+ def name
12
+ company_name
13
+ end
14
+
15
+ def number
16
+ company_number
17
+ end
18
+
19
+ def active?
20
+ company_status == "active"
21
+ end
22
+
23
+ def dissolved?
24
+ !active?
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ module CompaniesHouseClient
2
+ class Officer < Base
3
+ belongs_to :company
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module CompaniesHouseClient
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: companies_house_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ed Jones
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-03 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: require_all
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: her
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A REST client for the UK Companies House API, including authentication
70
+ email:
71
+ - ed@errorstudio.co.uk
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".ruby-gemset"
78
+ - ".ruby-version"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - companies_house_client.gemspec
84
+ - lib/companies_house_client.rb
85
+ - lib/companies_house_client/base.rb
86
+ - lib/companies_house_client/ca_path.rb
87
+ - lib/companies_house_client/collection_parser.rb
88
+ - lib/companies_house_client/models/company.rb
89
+ - lib/companies_house_client/models/officer.rb
90
+ - lib/companies_house_client/version.rb
91
+ homepage: https://github.com/errorstudio/companies_house_client
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.4.5.1
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: A REST client for the UK Companies House API
115
+ test_files: []