column_api 0.0.1 → 0.0.3

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
  SHA256:
3
- metadata.gz: 88259c47704f5f8107180c9e96b9382be8a069f645fb70422b690ac4233584b8
4
- data.tar.gz: dc3086ad497d5ebb3647c78250f6ff25a827b2bb3d5252f6c00199d178068f3f
3
+ metadata.gz: 1f6201925587745962ca88d181952fb299995347b0bcc66581ea2d39ecccdbc6
4
+ data.tar.gz: 9053f946825a96523e0d86867ded80df66d59b6c69254d814cd24bb135367820
5
5
  SHA512:
6
- metadata.gz: ef355750084f74d9530b42a6e6a1d1672dc8260856e264a073170c72d6fed12607e272661b3e074c33a3ad1ae615bcfff64a755318f41737b2728dd403b924a0
7
- data.tar.gz: e2ddf0b78305d4190a92195eaf128eaaba04e4d910626f5b6ef967cdc038dc42fd06bc31a4cb6fa302f0a101bab2eef1b4ec5f13659d3d99394229b5bf0f544e
6
+ metadata.gz: 4125ef91a2a974c38c935b2665bf1fb8af9e0e151bd42595e3cdb3bba7aa67e951b4c00a3b91a8a9321d3adfe49b635d3701840d178df7a5315f8174db36bcb5
7
+ data.tar.gz: ce6defb6e864690523b481813a1d0c1c0e0be8447712b73ad5c6548f294d8c3d519519b9626eb68176d4ba025165007bafa82e38ccbe83742eda70b20dd4ef75
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
- --format documentation
1
+ --format progress
2
2
  --color
3
3
  --require spec_helper
data/.rubocop.yml CHANGED
@@ -16,3 +16,9 @@ Layout/LineLength:
16
16
 
17
17
  Style/Documentation:
18
18
  Enabled: false
19
+
20
+ Style/OpenStructUse:
21
+ Enabled: false
22
+
23
+ Metrics/BlockLength:
24
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2023-12-29
3
+ ## [0.0.3] - 2024-01-02
4
+
5
+ - Add Bank Account endpoints
6
+
7
+ ## [0.0.2] - 2023-12-31
8
+
9
+ - Add Entity endpoints
10
+
11
+ ## [0.0.1] - 2023-12-29
4
12
 
5
13
  - Initial release
14
+ - Add Faraday client
data/Gemfile CHANGED
@@ -10,3 +10,5 @@ gem "rake", "~> 13.0"
10
10
  gem "rspec", "~> 3.0"
11
11
 
12
12
  gem "rubocop", "~> 1.21"
13
+
14
+ gem "webmock", "~> 3.19", ">= 3.19.1"
data/Gemfile.lock CHANGED
@@ -1,15 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- column_api (0.0.1)
4
+ column_api (0.0.3)
5
5
  faraday (~> 2.8.1)
6
6
  faraday-parse_dates (~> 0.1.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
+ addressable (2.8.6)
12
+ public_suffix (>= 2.0.2, < 6.0)
11
13
  ast (2.4.2)
12
14
  base64 (0.2.0)
15
+ crack (0.4.5)
16
+ rexml
13
17
  diff-lcs (1.5.0)
14
18
  faraday (2.8.1)
15
19
  base64
@@ -18,12 +22,14 @@ GEM
18
22
  faraday-net_http (3.0.2)
19
23
  faraday-parse_dates (0.1.1)
20
24
  faraday (~> 2.0)
25
+ hashdiff (1.1.0)
21
26
  json (2.7.1)
22
27
  language_server-protocol (3.17.0.3)
23
28
  parallel (1.24.0)
24
29
  parser (3.2.2.4)
25
30
  ast (~> 2.4.1)
26
31
  racc
32
+ public_suffix (5.0.4)
27
33
  racc (1.7.3)
28
34
  rainbow (3.1.1)
29
35
  rake (13.1.0)
@@ -58,6 +64,10 @@ GEM
58
64
  ruby-progressbar (1.13.0)
59
65
  ruby2_keywords (0.0.5)
60
66
  unicode-display_width (2.5.0)
67
+ webmock (3.19.1)
68
+ addressable (>= 2.8.0)
69
+ crack (>= 0.3.2)
70
+ hashdiff (>= 0.4.0, < 2.0.0)
61
71
 
62
72
  PLATFORMS
63
73
  arm64-darwin-22
@@ -68,6 +78,7 @@ DEPENDENCIES
68
78
  rake (~> 13.0)
69
79
  rspec (~> 3.0)
70
80
  rubocop (~> 1.21)
81
+ webmock (~> 3.19, >= 3.19.1)
71
82
 
72
83
  BUNDLED WITH
73
84
  2.4.13
data/README.md CHANGED
@@ -1,28 +1,71 @@
1
1
  # ColumnApi
2
2
 
3
- **WIP**
3
+ _This gem is under development and the API is unstable._
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/column_api.svg)](https://badge.fury.io/rb/column_api)
4
6
 
5
7
  Ruby bindings for [Column's API](https://column.com/docs/api).
6
8
 
7
9
  ## Installation
8
10
 
9
- gem "column_api", :git => "git://github.com/matiasleidemer/column_api.git"
11
+ ```ruby
12
+ gem 'column_api', '~> 0.0.3'
13
+ ```
10
14
 
11
15
  ## Usage
12
16
 
13
17
  ```ruby
14
18
  client = ColumnApi::Client.new(api_key: ENV["COLUMN_API_KEY"])
15
19
 
16
- client.connection.get("entities").body
17
- # => {"entities"=>[{"documents"=>[], "id"=>"enti_2aELWf6D", ...
20
+ person = client.entities.retrieve(entity_id: "enti_2aELWf6D")
21
+ person.id # => enti_2Q1ctiJm1NypVqCt8UBC8e4xTfH
22
+ person.person_details.email # => oliver@column.com
23
+
24
+ bank_accounts = client.bank_accounts.list({ limit: 2 })
25
+ bank_accounts.data # => [#<ColumnApi::BankAccount>, #<ColumnApi::BankAccount>]
26
+ bank_accounts.has_more # => true
27
+ ```
18
28
 
29
+ Alternatively, you can query the endpoints directly:
30
+
31
+ ```ruby
19
32
  client.connection.get("entities/enti_2aELWf6D").body
20
33
  # =>
21
34
  # {"documents"=>[],
22
35
  # "id"=>"enti_2aELWf6D",
23
36
  # "is_root"=>true,
24
37
  # "person_details"=> {...}
25
- # etc
38
+ # }
39
+ ```
40
+
41
+ ## Resources
42
+
43
+ ### Entities
44
+
45
+ https://column.com/docs/api/#entity/object
46
+
47
+ ```ruby
48
+ client.entities.list({})
49
+ client.entities.retrieve(entity_id: "ID")
50
+ client.entities.create_person({})
51
+ client.entities.create_business({})
52
+ client.entities.update_person(entity_id:, params: {})
53
+ client.entities.update_business(entity_id:, params: {})
54
+ client.entities.delete(entity_id: "ID")
55
+ client.entities.submit_document(entity_id: "ID", params: {})
56
+ ```
57
+
58
+ ### BankAccounts
59
+
60
+ https://column.com/docs/api/#bank-account/object
61
+
62
+ ```ruby
63
+ client.bank_accounts.list({})
64
+ client.bank_accounts.retrieve(bank_account_id: "ID")
65
+ client.bank_accounts.create({})
66
+ client.bank_accounts.update(bank_account_id: "ID", params: {})
67
+ client.bank_accounts.delete(bank_account_id: "ID")
68
+ client.bank_accounts.history(bank_account_id: "ID", from_date: Date, to_date: Date)
26
69
  ```
27
70
 
28
71
  ## Development
@@ -2,15 +2,22 @@
2
2
 
3
3
  module ColumnApi
4
4
  class Client
5
- BASE_URL = "https://api.column.com/"
5
+ attr_reader :api_key, :base_url, :adapter
6
6
 
7
- attr_reader :api_key, :adapter
8
-
9
- def initialize(api_key:, adapter: Faraday.default_adapter)
7
+ def initialize(api_key:, base_url: BASE_URL, adapter: Faraday.default_adapter)
10
8
  @api_key = api_key
9
+ @base_url = base_url
11
10
  @adapter = adapter
12
11
  end
13
12
 
13
+ def entities
14
+ EntityResource.new(self)
15
+ end
16
+
17
+ def bank_accounts
18
+ BankAccountResource.new(self)
19
+ end
20
+
14
21
  def connection
15
22
  @connection ||= Faraday.new(BASE_URL) do |conn|
16
23
  conn.request :authorization, :basic, "", api_key
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ColumnApi
4
+ class Collection
5
+ attr_reader :data, :has_more
6
+
7
+ def self.from_response(response, key:, type:)
8
+ new(
9
+ data: response[key].map do |attrs|
10
+ if type.respond_to?(:from_response)
11
+ type.from_response(attrs)
12
+ else
13
+ type.new(attrs)
14
+ end
15
+ end,
16
+ has_more: response["has_more"]
17
+ )
18
+ end
19
+
20
+ def initialize(data:, has_more:)
21
+ @data = data
22
+ @has_more = has_more
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ColumnApi
4
+ class Error < StandardError; end
5
+ class BadRequestError < StandardError; end
6
+ class UnauthorizedError < StandardError; end
7
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "ostruct"
5
+
6
+ module ColumnApi
7
+ class Object < OpenStruct
8
+ def initialize(attributes)
9
+ super(to_ostruct(attributes))
10
+ end
11
+
12
+ def to_ostruct(obj)
13
+ if obj.is_a?(Hash)
14
+ OpenStruct.new(obj.transform_values { |val| to_ostruct(val) })
15
+ elsif obj.is_a?(Array)
16
+ obj.map { |o| to_ostruct(o) }
17
+ else # Assumed to be a primitive value
18
+ obj
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ColumnApi
4
+ class BankAccount < Object
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ColumnApi
4
+ class BusinessEntity < Object
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ColumnApi
4
+ class PersonEntity < Object
5
+ end
6
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ColumnApi
4
+ class Resource
5
+ attr_reader :client
6
+
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ private
12
+
13
+ def get_request(url, params: {}, headers: {})
14
+ handle_response client.connection.get(url, params, headers)
15
+ end
16
+
17
+ def post_request(url, body:, headers: {})
18
+ handle_response client.connection.post(url, body, headers)
19
+ end
20
+
21
+ def patch_request(url, body:, headers: {})
22
+ handle_response client.connection.patch(url, body, headers)
23
+ end
24
+
25
+ def delete_request(url, params: {}, headers: {})
26
+ handle_response client.connection.delete(url, params, headers)
27
+ end
28
+
29
+ def handle_response(response)
30
+ case response.status
31
+ when 400
32
+ raise BadRequestError, response.body["message"]
33
+ when 401
34
+ raise UnauthorizedError, "Unauthorized"
35
+ end
36
+
37
+ response
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ColumnApi
4
+ class BankAccountResource < Resource
5
+ def list(params = {})
6
+ response = get_request("bank-accounts", params: params).body
7
+ Collection.from_response(response, key: "bank_accounts", type: BankAccount)
8
+ end
9
+
10
+ def retrieve(bank_account_id:)
11
+ BankAccount.new get_request("bank-accounts/#{bank_account_id}").body
12
+ end
13
+
14
+ def create(params)
15
+ BankAccount.new post_request("bank-accounts", body: params).body
16
+ end
17
+
18
+ def update(bank_account_id:, params:)
19
+ BankAccount.new patch_request("bank-accounts/#{bank_account_id}", body: params).body
20
+ end
21
+
22
+ def delete(bank_account_id:)
23
+ delete_request("bank-accounts/#{bank_account_id}")
24
+ true
25
+ end
26
+
27
+ def history(bank_account_id:, from_date:, to_date:)
28
+ params = { from_date: from_date.strftime("%Y-%m-%d"), to_date: to_date.strftime("%Y-%m-%d") }
29
+
30
+ BankAccount.new get_request("bank-accounts/#{bank_account_id}/history", params: params).body
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ColumnApi
4
+ class EntityResource < Resource
5
+ def self.from_response(response)
6
+ if response["type"] == "PERSON"
7
+ PersonEntity.new(response)
8
+ else
9
+ BusinessEntity.new(response)
10
+ end
11
+ end
12
+
13
+ def retrieve(entity_id:)
14
+ EntityResource.from_response get_request("entities/#{entity_id}").body
15
+ end
16
+
17
+ def list(params = {})
18
+ response = get_request("entities", params: params).body
19
+ Collection.from_response(response, key: "entities", type: EntityResource)
20
+ end
21
+
22
+ def create_person(params)
23
+ PersonEntity.new post_request("entities/person", body: params).body
24
+ end
25
+
26
+ def update_person(entity_id:, params:)
27
+ PersonEntity.new patch_request("entities/person/#{entity_id}", body: params).body
28
+ end
29
+
30
+ def create_business(params)
31
+ BusinessEntity.new post_request("entities/business", body: params).body
32
+ end
33
+
34
+ def update_business(entity_id:, params:)
35
+ BusinessEntity.new patch_request("entities/business/#{entity_id}", body: params).body
36
+ end
37
+
38
+ def delete(entity_id:)
39
+ delete_request("entities/#{entity_id}")
40
+ true
41
+ end
42
+
43
+ def submit_document(entity_id:, params:)
44
+ EntityResource.from_response(
45
+ post_request("entities/#{entity_id}/documents", body: params).body
46
+ )
47
+ end
48
+ end
49
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ColumnApi
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.3"
5
5
  end
data/lib/column_api.rb CHANGED
@@ -4,7 +4,22 @@ require "faraday"
4
4
  require "faraday/parse_dates"
5
5
 
6
6
  require_relative "column_api/version"
7
+ require_relative "column_api/errors"
7
8
 
8
9
  module ColumnApi
10
+ BASE_URL = "https://api.column.com/"
11
+
9
12
  autoload :Client, "column_api/client"
13
+ autoload :Object, "column_api/object"
14
+ autoload :Collection, "column_api/collection"
15
+ autoload :Resource, "column_api/resource"
16
+
17
+ # Objects
18
+ autoload :BankAccount, "column_api/objects/bank_account"
19
+ autoload :BusinessEntity, "column_api/objects/business_entity"
20
+ autoload :PersonEntity, "column_api/objects/person_entity"
21
+
22
+ # Resources
23
+ autoload :BankAccountResource, "column_api/resources/bank_account_resource"
24
+ autoload :EntityResource, "column_api/resources/entity_resource"
10
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: column_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matias Leidemer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-30 00:00:00.000000000 Z
11
+ date: 2024-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -54,9 +54,17 @@ files:
54
54
  - LICENSE.txt
55
55
  - README.md
56
56
  - Rakefile
57
- - column_api.gemspec
58
57
  - lib/column_api.rb
59
58
  - lib/column_api/client.rb
59
+ - lib/column_api/collection.rb
60
+ - lib/column_api/errors.rb
61
+ - lib/column_api/object.rb
62
+ - lib/column_api/objects/bank_account.rb
63
+ - lib/column_api/objects/business_entity.rb
64
+ - lib/column_api/objects/person_entity.rb
65
+ - lib/column_api/resource.rb
66
+ - lib/column_api/resources/bank_account_resource.rb
67
+ - lib/column_api/resources/entity_resource.rb
60
68
  - lib/column_api/version.rb
61
69
  - sig/column_api.rbs
62
70
  homepage: https://github.com/matiasleidemer/column_api
@@ -79,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
87
  - !ruby/object:Gem::Version
80
88
  version: '0'
81
89
  requirements: []
82
- rubygems_version: 3.4.10
90
+ rubygems_version: 3.4.6
83
91
  signing_key:
84
92
  specification_version: 4
85
93
  summary: Ruby bindings for Column API
data/column_api.gemspec DELETED
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/column_api/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "column_api"
7
- spec.version = ColumnApi::VERSION
8
- spec.authors = ["Matias Leidemer"]
9
- spec.email = ["matiasleidemer@gmail.com"]
10
-
11
- spec.summary = "Ruby bindings for Column API"
12
- spec.description = "Ruby bindings for Column API. https://column.com/docs/api"
13
- spec.homepage = "https://github.com/matiasleidemer/column_api"
14
- spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.6.0"
16
-
17
- spec.metadata["rubygems_mfa_required"] = "true"
18
-
19
- # Specify which files should be added to the gem when it is released.
20
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
- spec.files = Dir.chdir(__dir__) do
22
- `git ls-files -z`.split("\x0").reject do |f|
23
- (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
24
- end
25
- end
26
- spec.bindir = "exe"
27
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
29
-
30
- spec.add_dependency "faraday", "~> 2.8.1"
31
- spec.add_dependency "faraday-parse_dates", "~> 0.1.1"
32
- end