column_api 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88259c47704f5f8107180c9e96b9382be8a069f645fb70422b690ac4233584b8
4
- data.tar.gz: dc3086ad497d5ebb3647c78250f6ff25a827b2bb3d5252f6c00199d178068f3f
3
+ metadata.gz: 73530bf2a0b110c13bd34d55231cc3e0d91ff44046221a7b74ea8ec2b380ef82
4
+ data.tar.gz: f41a16e9e40eff65511e43e85238708fe6c54027a8f006cdfe0d8fac8ad02533
5
5
  SHA512:
6
- metadata.gz: ef355750084f74d9530b42a6e6a1d1672dc8260856e264a073170c72d6fed12607e272661b3e074c33a3ad1ae615bcfff64a755318f41737b2728dd403b924a0
7
- data.tar.gz: e2ddf0b78305d4190a92195eaf128eaaba04e4d910626f5b6ef967cdc038dc42fd06bc31a4cb6fa302f0a101bab2eef1b4ec5f13659d3d99394229b5bf0f544e
6
+ metadata.gz: e3af56a1cf2c39c8f2e073fcefb302f9aec329c6f578c63e628c10aac54b88d5ac9493b57d77a270f24895bd8578eecdac02b65848a125399c79a4b056b925ba
7
+ data.tar.gz: 319b6972c7d192ad2900d8f7baf805fcdfd9fd90d0ed3a77afb0724b00f4341661abd67be927a4f8757f0ec4dd9a160dcc389dd88340992280b31977becdfa39
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/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.2)
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,53 @@
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.2'
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
+ client.entities.retrieve(entity_id: "enti_2aELWf6D")
21
+ # => #<ColumnApi::PersonEntity documents=[], id="enti_2aELWf6D", is_root=true, type="PERSON" (...)>
22
+ ```
23
+
24
+ Alternatively, you can query the endpoints directly:
18
25
 
26
+ ```ruby
19
27
  client.connection.get("entities/enti_2aELWf6D").body
20
28
  # =>
21
29
  # {"documents"=>[],
22
30
  # "id"=>"enti_2aELWf6D",
23
31
  # "is_root"=>true,
24
32
  # "person_details"=> {...}
25
- # etc
33
+ # }
34
+ ```
35
+
36
+ ## Resources
37
+
38
+ ### Entities
39
+
40
+ https://column.com/docs/api/#entity/object
41
+
42
+ ```ruby
43
+ client.entities.list({})
44
+ client.entities.retrieve(entity_id: "ID")
45
+ client.entities.create_person({})
46
+ client.entities.create_business({})
47
+ client.entities.update_person(entity_id:, params: {})
48
+ client.entities.update_business(entity_id:, params: {})
49
+ client.entities.delete(entity_id: "ID")
50
+ client.entities.submit_document(entity_id: "ID", params: {})
26
51
  ```
27
52
 
28
53
  ## Development
@@ -2,15 +2,18 @@
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
+
14
17
  def connection
15
18
  @connection ||= Faraday.new(BASE_URL) do |conn|
16
19
  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,16 @@
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
+ JSON.parse obj.to_json, object_class: OpenStruct
14
+ end
15
+ end
16
+ 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,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.2"
5
5
  end
data/lib/column_api.rb CHANGED
@@ -4,7 +4,20 @@ 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 :BusinessEntity, "column_api/objects/business_entity"
19
+ autoload :PersonEntity, "column_api/objects/person_entity"
20
+
21
+ # Resources
22
+ autoload :EntityResource, "column_api/resources/entity_resource"
10
23
  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.2
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: 2023-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -54,9 +54,15 @@ 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/business_entity.rb
63
+ - lib/column_api/objects/person_entity.rb
64
+ - lib/column_api/resource.rb
65
+ - lib/column_api/resources/entity_resource.rb
60
66
  - lib/column_api/version.rb
61
67
  - sig/column_api.rbs
62
68
  homepage: https://github.com/matiasleidemer/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