sellsy_v2 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: e81b80f3ade44f79cd2d68f01cc78ff537b5c889092d5af473a17d312fbebb7a
4
+ data.tar.gz: 05daf7bfed51a352d32c4e9ecdd451dd3056d9595a73913f8365b8a4d60d9048
5
+ SHA512:
6
+ metadata.gz: 410a23290c99d6b1f020aab7a12ef01515f63ed4c309ed6531c9ded7088a95898bd3c70669ca661e3ee43580b2efe44cc3a9bcd300ddb98c3ab8f36c801624e3
7
+ data.tar.gz: 2cdfc67f1211736cdfe37fc29865c691dea88ad258790b081afa89a79964aa3446ec2fa013d084e480f9d028ceedc7bce58abbe74ea84e2a41c03e0cd59a7e15
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
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,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-09-20
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in sellsy_v2.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "rubocop", "~> 1.7"
data/Gemfile.lock ADDED
@@ -0,0 +1,112 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sellsy_v2 (0.1.0)
5
+ json
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionpack (6.1.4.1)
11
+ actionview (= 6.1.4.1)
12
+ activesupport (= 6.1.4.1)
13
+ rack (~> 2.0, >= 2.0.9)
14
+ rack-test (>= 0.6.3)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
17
+ actionview (6.1.4.1)
18
+ activesupport (= 6.1.4.1)
19
+ builder (~> 3.1)
20
+ erubi (~> 1.4)
21
+ rails-dom-testing (~> 2.0)
22
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
23
+ activesupport (6.1.4.1)
24
+ concurrent-ruby (~> 1.0, >= 1.0.2)
25
+ i18n (>= 1.6, < 2)
26
+ minitest (>= 5.1)
27
+ tzinfo (~> 2.0)
28
+ zeitwerk (~> 2.3)
29
+ addressable (2.8.0)
30
+ public_suffix (>= 2.0.2, < 5.0)
31
+ ast (2.4.2)
32
+ builder (3.2.4)
33
+ concurrent-ruby (1.1.9)
34
+ crack (0.4.5)
35
+ rexml
36
+ crass (1.0.6)
37
+ dotenv (2.7.6)
38
+ dotenv-rails (2.7.6)
39
+ dotenv (= 2.7.6)
40
+ railties (>= 3.2)
41
+ erubi (1.10.0)
42
+ hashdiff (1.0.1)
43
+ i18n (1.8.10)
44
+ concurrent-ruby (~> 1.0)
45
+ json (2.5.1)
46
+ loofah (2.12.0)
47
+ crass (~> 1.0.2)
48
+ nokogiri (>= 1.5.9)
49
+ method_source (1.0.0)
50
+ minitest (5.14.4)
51
+ nokogiri (1.12.4-x86_64-darwin)
52
+ racc (~> 1.4)
53
+ parallel (1.21.0)
54
+ parser (3.0.2.0)
55
+ ast (~> 2.4.1)
56
+ public_suffix (4.0.6)
57
+ racc (1.5.2)
58
+ rack (2.2.3)
59
+ rack-test (1.1.0)
60
+ rack (>= 1.0, < 3)
61
+ rails-dom-testing (2.0.3)
62
+ activesupport (>= 4.2.0)
63
+ nokogiri (>= 1.6)
64
+ rails-html-sanitizer (1.4.2)
65
+ loofah (~> 2.3)
66
+ railties (6.1.4.1)
67
+ actionpack (= 6.1.4.1)
68
+ activesupport (= 6.1.4.1)
69
+ method_source
70
+ rake (>= 0.13)
71
+ thor (~> 1.0)
72
+ rainbow (3.0.0)
73
+ rake (13.0.6)
74
+ regexp_parser (2.1.1)
75
+ rexml (3.2.5)
76
+ rubocop (1.21.0)
77
+ parallel (~> 1.10)
78
+ parser (>= 3.0.0.0)
79
+ rainbow (>= 2.2.2, < 4.0)
80
+ regexp_parser (>= 1.8, < 3.0)
81
+ rexml
82
+ rubocop-ast (>= 1.9.1, < 2.0)
83
+ ruby-progressbar (~> 1.7)
84
+ unicode-display_width (>= 1.4.0, < 3.0)
85
+ rubocop-ast (1.11.0)
86
+ parser (>= 3.0.1.1)
87
+ ruby-progressbar (1.11.0)
88
+ thor (1.1.0)
89
+ tzinfo (2.0.4)
90
+ concurrent-ruby (~> 1.0)
91
+ unicode-display_width (2.1.0)
92
+ vcr (6.0.0)
93
+ webmock (3.14.0)
94
+ addressable (>= 2.8.0)
95
+ crack (>= 0.3.2)
96
+ hashdiff (>= 0.4.0, < 2.0.0)
97
+ zeitwerk (2.4.2)
98
+
99
+ PLATFORMS
100
+ x86_64-darwin-20
101
+
102
+ DEPENDENCIES
103
+ dotenv-rails
104
+ minitest (~> 5.0)
105
+ rake (~> 13.0)
106
+ rubocop (~> 1.7)
107
+ sellsy_v2!
108
+ vcr
109
+ webmock
110
+
111
+ BUNDLED WITH
112
+ 2.2.20
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Victor Holl
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,39 @@
1
+ # SellsyV2
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sellsy_v2`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sellsy_v2'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sellsy_v2
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sellsy_v2.
36
+
37
+ ## License
38
+
39
+ 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,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test 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 "sellsy_v2"
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/gitignore ADDED
File without changes
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ require 'json'
3
+
4
+ module SellsyV2
5
+ class Company
6
+ class Address
7
+
8
+ def initialize(attr)
9
+ attr.each do |k,v|
10
+ define_singleton_method(k) { instance_variable_get("@#{k}") }
11
+ define_singleton_method("#{k}=") { |val| instance_variable_set("@#{k}", val) }
12
+
13
+ instance_variable_set("@#{k}", v)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+ require 'json'
3
+
4
+ module SellsyV2
5
+ class Company
6
+ ROOT_PATH = '/companies'
7
+
8
+ def initialize(attr)
9
+ attr.each do |k,v|
10
+ define_singleton_method(k) { instance_variable_get("@#{k}") }
11
+ define_singleton_method("#{k}=") { |val| instance_variable_set("@#{k}", val) }
12
+
13
+ instance_variable_set("@#{k}", v)
14
+ end
15
+ end
16
+
17
+ def self.all(**options)
18
+ companies_response = Request.new(path: ROOT_PATH, verb: 'get', options: options).call
19
+ if companies_response.success?
20
+ companies_response.data.dig('data').map{Company.new(_1)}
21
+ end
22
+ end
23
+
24
+ def self.find(id, **options)
25
+ company_response = Request.new(path: "#{ROOT_PATH}/#{id}", verb: 'get', options: options).call
26
+ if company_response.success?
27
+ Company.new(company_response.data)
28
+ end
29
+ end
30
+
31
+ def addresses(**options)
32
+ verb = 'get'
33
+ path = "#{ROOT_PATH}/#{id}/addresses"
34
+ company_addresses_response = Request.new(path: path, verb: verb, options: options).call
35
+ if company_addresses_response.success?
36
+ company_addresses_response.data.dig('data').map{Address.new(_1)}
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,23 @@
1
+ module SellsyV2
2
+ module Config
3
+ extend self
4
+
5
+ attr_accessor :token
6
+
7
+ def reset
8
+ self.token = nil
9
+ end
10
+
11
+ reset
12
+ end
13
+
14
+ class << self
15
+ def configure
16
+ block_given? ? yield(Config) : Config
17
+ end
18
+
19
+ def config
20
+ Config
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SellsyV2
4
+ VERSION = "0.1.0"
5
+ end
data/lib/sellsy_v2.rb ADDED
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "sellsy_v2/version"
4
+ require_relative "sellsy_v2/company"
5
+ require_relative "sellsy_v2/company/address"
6
+
7
+ module SellsyV2
8
+ class Error < StandardError; end
9
+ # Your code goes here...
10
+ class Request
11
+ require "uri"
12
+ require "net/http"
13
+ require "json"
14
+
15
+ def initialize(verb:, path:, options:)
16
+ params = '?' + options.map{|k,v| v.class == Array ? "#{k}[]=#{v.join(',')}" : "#{k}=#{v}"}.join('&')
17
+ @url = URI("https://api.sellsy.com/v2#{path}#{params}")
18
+ end
19
+
20
+ def call
21
+ https = Net::HTTP.new(@url.host, @url.port)
22
+ https.use_ssl = true
23
+
24
+ request = Net::HTTP::Get.new(@url) # change to verb
25
+ request["Authorization"] = ENV["SELLSY_TOKEN"]
26
+
27
+ response = https.request(request)
28
+
29
+ if response.is_a?(Net::HTTPOK)
30
+ OpenStruct.new(success?: true, data: JSON.parse(response.read_body))
31
+ else
32
+ OpenStruct.new(success?: false, data: response)
33
+ end
34
+ end
35
+ end
36
+
37
+ class Search
38
+ ROOT_PATH = '/search'
39
+
40
+ def initialize(query:, **options)
41
+ search_response = Request.new(path: ROOT_PATH, verb: 'get', options: options.merge({q: query})).call
42
+ if search_response.success?
43
+ search_response.data.dig('data').map{OpenStruct.new(_1)}
44
+ end
45
+ end
46
+ end
47
+ end
data/sellsy_v2.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/sellsy_v2/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "sellsy_v2"
7
+ spec.version = SellsyV2::VERSION
8
+ spec.authors = ["Victor Holl"]
9
+ spec.email = ["v_h@me.com"]
10
+
11
+ spec.summary = "Very simple and basic RESTClient for Sellsy V2 API"
12
+ spec.homepage = "https://www.vho.fr"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.4.0"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/v-h-z/sellsy_v2"
20
+ spec.metadata["changelog_uri"] = "https://github.com/v-h-z/sellsy_v2/CHANGELOG.md"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ # Uncomment to register a new dependency of your gem
32
+ # spec.add_dependency "example-gem", "~> 1.0"
33
+ spec.add_development_dependency "minitest"
34
+ spec.add_development_dependency "vcr"
35
+ spec.add_development_dependency "webmock"
36
+
37
+ spec.add_dependency "json"
38
+
39
+ # For more information and examples about making a new gem, checkout our
40
+ # guide at: https://bundler.io/guides/creating_gem.html
41
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sellsy_v2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Victor Holl
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-09-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: vcr
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
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: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - v_h@me.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".DS_Store"
77
+ - ".gitignore"
78
+ - ".rubocop.yml"
79
+ - CHANGELOG.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - gitignore
88
+ - lib/sellsy_v2.rb
89
+ - lib/sellsy_v2/company.rb
90
+ - lib/sellsy_v2/company/address.rb
91
+ - lib/sellsy_v2/config.rb
92
+ - lib/sellsy_v2/version.rb
93
+ - sellsy_v2.gemspec
94
+ homepage: https://www.vho.fr
95
+ licenses:
96
+ - MIT
97
+ metadata:
98
+ allowed_push_host: https://rubygems.org
99
+ homepage_uri: https://www.vho.fr
100
+ source_code_uri: https://github.com/v-h-z/sellsy_v2
101
+ changelog_uri: https://github.com/v-h-z/sellsy_v2/CHANGELOG.md
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 2.4.0
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubygems_version: 3.1.6
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Very simple and basic RESTClient for Sellsy V2 API
121
+ test_files: []