spyri-api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/spyri-api.rb +7 -0
- data/lib/spyri_api/client.rb +45 -0
- data/lib/spyri_api/error.rb +24 -0
- data/lib/spyri_api/invoices.rb +31 -0
- data/lib/spyri_api/subscriptions.rb +36 -0
- data/lib/spyri_api/users.rb +41 -0
- data/lib/spyri_api/version.rb +5 -0
- data/spyri-api.gemspec +31 -0
- metadata +78 -0
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
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
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
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
data/lib/spyri-api.rb
ADDED
@@ -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
|
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: []
|