companies_house_api 0.1.2

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: cdcf097862f3405032d89f74165de56710aa2463
4
+ data.tar.gz: 38ced24922179e233896e275499b22a03aef4c50
5
+ SHA512:
6
+ metadata.gz: aeed0bfd26ea51948654234ecaf67f38e9883325b17eff464cd140e72c36f90e03fde888267b53fd7dc72b65efe47a15ea5ae52166bef46cb19b08d0a07ee62f
7
+ data.tar.gz: b455e7a6e1640e08d22a1332d6e4395b09581ac9def31102114a15177ff6ca9847bd1008c43057072efc2d710832a48a20fe3afbb2803c175996cd8c61b23c28
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ api_key_tmp.yml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in companies_house_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Robin Fisher
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # CompaniesHouse
2
+
3
+ The CompaniesHouse gem provides a wrapper around the Companies House API. Two methods are currently provided. One to search the Companies House database against a given string. The second to retrieve company information given a company number.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'companies_house_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install companies_house_api
20
+
21
+ ## Usage
22
+
23
+ An API key is required which can be obtained by registering with [Companies House](https://developer.companieshouse.gov.uk/api/docs/index/gettingStarted/apikey_authorisation.html).
24
+
25
+ Configure the gem using a block in an initializer:
26
+
27
+ ```ruby
28
+ CompaniesHouse.configure do |config|
29
+ config.api_key = "your_api_key_here"
30
+ end
31
+ ```
32
+
33
+ Planning ahead for future development, there are two classes, `Search` and `Company Information`.
34
+
35
+ To search for company information, configure as above and then instantiate a new instance of the `Search` class.
36
+
37
+ ```ruby
38
+ ch = CompaniesHouse::Search.new
39
+ ch.search_companies("captured sparks")
40
+ ```
41
+
42
+ This returns a plain ruby object with two attributes: a count of how many results are returned for the search and an array of those results.
43
+
44
+ To retrieve company information:
45
+
46
+ ```ruby
47
+ ch = CompaniesHouse::CompanyInformation.new
48
+ ch.company_profile("07577596")
49
+ ```
50
+
51
+ Again, this return a plain ruby object with attributes as shown in the API documentation e.g. `company_name`.
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it ( https://github.com/[my-github-username]/companies_house_api/fork )
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "companies_house_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
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/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "companies_house_api"
8
+ spec.version = CompaniesHouse::VERSION
9
+ spec.authors = ["Robin Fisher"]
10
+ spec.email = ["robinjfisher@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby library for interacting with Companies House API}
13
+ spec.homepage = "https://github.com/robinjfisher/companies_house_api"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.9"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.2"
24
+ spec.add_development_dependency "json"
25
+ spec.add_development_dependency "faraday", "~> 0.9.2"
26
+ spec.add_development_dependency "mocha", "~> 1.1.0"
27
+ spec.add_development_dependency "webmock", "~> 1.24"
28
+ end
@@ -0,0 +1,24 @@
1
+ module CompaniesHouse
2
+
3
+ class Base
4
+
5
+ API_URL = "https://api.companieshouse.gov.uk/"
6
+
7
+ attr_accessor :api_key
8
+
9
+ def initialize
10
+ if CompaniesHouse.configuration.nil?
11
+ raise ApiKeyError.new("You have not set an API key")
12
+ end
13
+ self.api_key = CompaniesHouse.configuration.api_key
14
+ @@conn = Faraday.new(:url => API_URL) do |faraday|
15
+ faraday.response :logger
16
+ faraday.adapter Faraday.default_adapter
17
+ end
18
+ @@conn.headers[:authorization] = "#{@api_key}"
19
+ @@conn.basic_auth("#{api_key}","")
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,25 @@
1
+ module CompaniesHouse
2
+
3
+ class CompanyInformation < Base
4
+
5
+ def initialize
6
+ super
7
+ end
8
+
9
+ def company_profile(company_number)
10
+ # GET /company/company_number
11
+ url = "company/#{company_number}"
12
+ response = @@conn.get url
13
+ result = JSON.parse(response.body, object_class: OpenStruct)
14
+ if result.respond_to?(:errors)
15
+ if result.errors[0][:error] == "company-profile-not-found"
16
+ raise CompanyNotFoundError.new("A company with that registration number could not be found")
17
+ end
18
+ else
19
+ return result
20
+ end
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,26 @@
1
+ module CompaniesHouse
2
+
3
+ # CompaniesHouse.configure do |config|
4
+ # config.api_key = '837432u32hlfkwjhkljehw'
5
+ # end
6
+
7
+ class << self
8
+ attr_accessor :configuration
9
+ end
10
+
11
+ def self.configure
12
+ self.configuration ||= Configuration.new
13
+ yield(configuration)
14
+ end
15
+
16
+ class Configuration
17
+
18
+ attr_accessor :api_key
19
+
20
+ def initialize
21
+ @api_key = "example_api_key"
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,34 @@
1
+ module CompaniesHouse
2
+
3
+ class Search < Base
4
+
5
+ # request = CompaniesHouse::Search.new
6
+
7
+ def initialize
8
+ super
9
+ end
10
+
11
+ # search_companies
12
+ # https://developer.companieshouse.gov.uk/api/docs/search/companies/companysearch.html
13
+ # response = request.search_companies(query_string,items_per_page,start_index)
14
+ # query_string is a string to be searched for
15
+ # items_per_page is a string setting how many items to return per page
16
+ # start_index is a string representing the index of the first result item to return
17
+ # response.companies_count returns the number of companies found for the given query string
18
+ # response.companies returns an array of OpenStruct objects representing the company information found for the given query string
19
+
20
+ def search_companies(q="captured sparks",items_per_page="50",start_index="0")
21
+ # GET /search/companies
22
+ query_string = "?q=#{q}&items_per_page=#{items_per_page}"
23
+ unless start_index.nil?
24
+ query_string << "&start_index=#{start_index}"
25
+ end
26
+ url = "search/companies#{query_string}"
27
+ response = @@conn.get(url)
28
+ result = JSON.parse(response.body, object_class: OpenStruct)
29
+ return OpenStruct.new({companies_count: result.items.count, companies: result.items})
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,3 @@
1
+ module CompaniesHouse
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,18 @@
1
+ require 'yaml'
2
+ require 'json'
3
+ require 'faraday'
4
+ require "companies_house/version"
5
+ require 'companies_house/base'
6
+ require 'companies_house/configuration'
7
+ require 'companies_house/search'
8
+ require 'companies_house/company_information'
9
+
10
+ module CompaniesHouse
11
+
12
+ class ApiKeyError < StandardError
13
+ end
14
+
15
+ class CompanyNotFoundError < StandardError
16
+ end
17
+
18
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: companies_house_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Robin Fisher
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-25 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.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
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.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
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: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.9.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.9.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: mocha
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.1.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.24'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.24'
111
+ description:
112
+ email:
113
+ - robinjfisher@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - bin/console
125
+ - bin/setup
126
+ - companies_house_api.gemspec
127
+ - lib/companies_house.rb
128
+ - lib/companies_house/base.rb
129
+ - lib/companies_house/company_information.rb
130
+ - lib/companies_house/configuration.rb
131
+ - lib/companies_house/search.rb
132
+ - lib/companies_house/version.rb
133
+ homepage: https://github.com/robinjfisher/companies_house_api
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.4.5
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Ruby library for interacting with Companies House API
157
+ test_files: []