spyri-api 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e5555a66d22f3d689dbf782661c89edcbc6b15df460476d4d7d78265ff64ddd7
4
+ data.tar.gz: 8ce1848cae2871ee384175e3c7e283aa0ab5c5b29d2f3fd265652a04961411e3
5
+ SHA512:
6
+ metadata.gz: 721e0f90724e9504cfd950b8da10fb8486364c6cf2d6842c7b85241169d28f737bb717cc1b9c8078828be43ddb34bbdd39b3cf50373844a0eedd3732b5d3afec
7
+ data.tar.gz: fcc9dec7defab91c3996a0400ee60ef96db7296d355f7296636cff4785b339fe224b24fe3c6dcb9dcb8a862e4db3124d535a320be10d0f14d59a1cae1e8df8c9
data/.DS_Store ADDED
Binary file
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## [0.1.0] - 2024-11-06
2
+
3
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in spyri-api.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "rspec", "~> 3.0"
10
+ gem "rubocop", "~> 1.21"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Le Temps
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,58 @@
1
+ # SpyriApi
2
+
3
+ Ruby client library for the Spyri API
4
+
5
+ ## Installation
6
+
7
+ ### RubyGems
8
+
9
+ Just excute:
10
+
11
+ $ bundle add 'spyri-api'
12
+
13
+ ### Manually
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'spyri-api'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle install
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install spyri-api
28
+
29
+ ## Usage
30
+
31
+ ### Quickstart
32
+
33
+ ```ruby
34
+ begin
35
+ client = SpyriApi::Client.new
36
+ client.set_config({
37
+ access_token: 'YOUR_SPYRI_API_TOKEN',
38
+ host: 'YOUR_SPYRI_API_URL'
39
+ })
40
+ users_endpoint = SpyriApi::Users.new(client)
41
+ results = users_endpoint.search(email: "toto@test.com")
42
+ p results
43
+ rescue SpyriApi::Error => e
44
+ puts "Error: #{e}"
45
+ end
46
+ ```
47
+
48
+ ## API Documentation
49
+
50
+ You can find documentation about the Spyri API on the [developers website](https://developers.letemps.ch/)
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/letemps-ch/spyri-api.
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "spyri_api"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/spyri-api.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spyri_api/client"
4
+ require "spyri_api/error"
5
+ require "spyri_api/invoices"
6
+ require "spyri_api/subscriptions"
7
+ require "spyri_api/users"
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SpyriApi
4
+ class Client
5
+
6
+ def initialize(config = {})
7
+ set_config(config)
8
+ end
9
+
10
+ def set_config(config = {})
11
+ @access_token = config[:access_token] || ''
12
+ @host = config[:host] || ''
13
+
14
+ timeout = config[:timeout] || 120
15
+ @write_timeout = config[:write_timeout] || timeout
16
+ @read_timeout = config[:read_timeout] || timeout
17
+ @connect_timeout = config[:connect_timeout] || timeout
18
+ end
19
+
20
+ def call_api(http_method, path, opts = {})
21
+ headers = {'Content-Type' => "application/json"}
22
+ headers[:Authorization] = "Bearer #{@access_token}"
23
+
24
+ conn = Excon.new(@host + path, headers: headers, read_timeout: @read_timeout, write_timeout: @write_timeout, connect_timeout: @connect_timeout)
25
+
26
+ res = nil
27
+ case http_method.to_sym.downcase
28
+ when :post, :put, :patch, :delete
29
+ res = conn.request(method: http_method, query: opts[:query_params], body: opts[:body].to_json)
30
+ when :get
31
+ res = conn.get(query: opts[:query_params])
32
+ end
33
+
34
+ data = nil
35
+ data = JSON.parse(res.body) if res.status == 200
36
+
37
+ if (!data)
38
+ return Error.new(res.status, res.body)
39
+ end
40
+
41
+ return data
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SpyriApi
4
+ class Error < StandardError
5
+
6
+ attr_reader :status, :code, :details
7
+
8
+ def initialize(status, body)
9
+ @status = status
10
+ if @status == 404
11
+ @code = 'not_found'
12
+ else
13
+ data = JSON.parse(body)
14
+ @code = data['code']
15
+ @details = data['details']
16
+ end
17
+ super @code
18
+ end
19
+
20
+ def inspect
21
+ "<#{self.class}: #{instance_variables.map { |v| "#{v}=#{instance_variable_get(v)}"}.join(', ')}>"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SpyriApi
4
+ class Invoices
5
+
6
+ BASEPATH = '/invoices'.freeze
7
+
8
+ attr_accessor :api_client
9
+
10
+ def initialize(api_client)
11
+ @api_client = api_client
12
+ end
13
+
14
+ def search(opts = {})
15
+ query_params = {}
16
+ [:code, :subscription_id, :user_id].each do |key|
17
+ query_params[key.to_s] = opts[key] if !opts[key].blank?
18
+ end
19
+ path = BASEPATH
20
+ data = @api_client.call_api(:GET, path, query_params: query_params)
21
+ return data
22
+ end
23
+
24
+ def get(id)
25
+ path = "#{BASEPATH}/#{id}"
26
+ data = @api_client.call_api(:GET, path)
27
+ return data
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SpyriApi
4
+ class Subscriptions
5
+
6
+ BASEPATH = '/subscriptions'.freeze
7
+
8
+ attr_accessor :api_client
9
+
10
+ def initialize(api_client)
11
+ @api_client = api_client
12
+ end
13
+
14
+ def search(opts = {})
15
+ query_params = {}
16
+ [:erp_id].each do |key|
17
+ query_params[key.to_s] = opts[key] if !opts[key].blank?
18
+ end
19
+ path = BASEPATH
20
+ data = @api_client.call_api(:GET, path, query_params: query_params)
21
+ return data
22
+ end
23
+
24
+ def get(id)
25
+ path = "#{BASEPATH}/#{id}"
26
+ data = @api_client.call_api(:GET, path)
27
+ return data
28
+ end
29
+
30
+ def create(subscription_object)
31
+ path = BASEPATH
32
+ data = @api_client.call_api(:POST, path, body: { subscription: subscription_object })
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SpyriApi
4
+ class Users
5
+
6
+ BASEPATH = '/users'.freeze
7
+
8
+ attr_accessor :api_client
9
+
10
+ def initialize(api_client)
11
+ @api_client = api_client
12
+ end
13
+
14
+ def search(opts = {})
15
+ query_params = {}
16
+ [:email, :name, :phone_number, :erp_id].each do |key|
17
+ query_params[key.to_s] = opts[key] if !opts[key].blank?
18
+ end
19
+ path = BASEPATH
20
+ data = @api_client.call_api(:GET, path, query_params: query_params)
21
+ return data
22
+ end
23
+
24
+ def get(id)
25
+ path = "#{BASEPATH}/#{id}"
26
+ data = @api_client.call_api(:GET, path)
27
+ return data
28
+ end
29
+
30
+ def create(user_object)
31
+ path = BASEPATH
32
+ data = @api_client.call_api(:POST, path, body: { user: user_object })
33
+ end
34
+
35
+ def update(id, user_object)
36
+ path = "#{BASEPATH}/#{id}"
37
+ data = @api_client.call_api(:PATCH, path, body: { user: user_object })
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SpyriApi
4
+ VERSION = "0.1.0"
5
+ end
data/spyri-api.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/spyri_api/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "spyri-api"
7
+ spec.version = SpyriApi::VERSION
8
+ spec.authors = ["pabois"]
9
+ spec.email = ["pierreandre.boissinot@noesya.coop"]
10
+
11
+ spec.summary = "Ruby client library for the Spyri API"
12
+ spec.homepage = "https://github.com/letemps-ch/spyri-api"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/letemps-ch/spyri-api"
18
+ spec.metadata["changelog_uri"] = "https://github.com/letemps-ch/spyri-api/CHANGELOG.md"
19
+
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject do |f|
22
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
23
+ end
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "excon"
30
+
31
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spyri-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - pabois
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-11-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: excon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - pierreandre.boissinot@noesya.coop
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".DS_Store"
35
+ - ".rspec"
36
+ - ".rubocop.yml"
37
+ - CHANGELOG.md
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/setup
44
+ - lib/spyri-api.rb
45
+ - lib/spyri_api/client.rb
46
+ - lib/spyri_api/error.rb
47
+ - lib/spyri_api/invoices.rb
48
+ - lib/spyri_api/subscriptions.rb
49
+ - lib/spyri_api/users.rb
50
+ - lib/spyri_api/version.rb
51
+ - spyri-api.gemspec
52
+ homepage: https://github.com/letemps-ch/spyri-api
53
+ licenses:
54
+ - MIT
55
+ metadata:
56
+ homepage_uri: https://github.com/letemps-ch/spyri-api
57
+ source_code_uri: https://github.com/letemps-ch/spyri-api
58
+ changelog_uri: https://github.com/letemps-ch/spyri-api/CHANGELOG.md
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 2.6.0
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.1.4
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Ruby client library for the Spyri API
78
+ test_files: []