fantasticstay_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d6d5c86f2b9a796698def2e4b8801e4801de74335ac43f5e9bc2939814105cba
4
+ data.tar.gz: e9f2c55526493914d927c03c4830a8d46024fe38abe6b66a04a15418d5e532a7
5
+ SHA512:
6
+ metadata.gz: ee9371e6284a6ec29a4275ee1a28fe430e9604125e3d2ad9c29ff3946d27290e936830ff8cb875dd285ee02ff7fedcde8576012b01b2b84c01fd93a25af52e5b
7
+ data.tar.gz: '09de71f00f8d730c8eb8416703e10f8c4d028123ce150fa7fa9ae860e2be9a5d55fc215cec2a3feb381b524f5e4b03e9b073c56aff9cc555c5971875e4fc6ee5'
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.0
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.3
17
+ bundle install
18
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # project files
14
+ /.idea/
15
+ fantasticstay_api.iml
16
+
17
+ # custom ignores
18
+ .env
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ Style/StringLiterals:
2
+ Enabled: true
3
+ EnforcedStyle: single_quotes
4
+
5
+ Style/StringLiteralsInInterpolation:
6
+ Enabled: true
7
+ EnforcedStyle: double_quotes
8
+
9
+ Layout/LineLength:
10
+ Max: 120
11
+
12
+ AllCops:
13
+ TargetRubyVersion: 2.4.0
14
+ NewCops: enable
data/CHANGELOG.md ADDED
File without changes
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Dockerfile ADDED
@@ -0,0 +1,8 @@
1
+ FROM ruby:3.0
2
+
3
+ WORKDIR /usr/src/app
4
+
5
+ COPY . .
6
+
7
+ RUN bundle install
8
+
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in fantasticstay_api.gemspec
6
+ gemspec
7
+
8
+ gem 'dotenv', '~> 2.7'
9
+
10
+ group :test do
11
+ gem 'rake', '~> 13.0'
12
+ gem 'rspec', '~> 3.0'
13
+ gem 'rubocop', '~> 0.80'
14
+ gem 'vcr', '~> 6.0'
15
+ gem 'webmock', '~> 3.12'
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fantasticstay_api (0.1.0)
5
+ faraday (~> 1.3.0)
6
+ oj (~> 3.11)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ ast (2.4.2)
14
+ crack (0.4.5)
15
+ rexml
16
+ diff-lcs (1.4.4)
17
+ dotenv (2.7.6)
18
+ faraday (1.3.0)
19
+ faraday-net_http (~> 1.0)
20
+ multipart-post (>= 1.2, < 3)
21
+ ruby2_keywords
22
+ faraday-net_http (1.0.1)
23
+ hashdiff (1.0.1)
24
+ multipart-post (2.1.1)
25
+ oj (3.11.3)
26
+ parallel (1.20.1)
27
+ parser (3.0.0.0)
28
+ ast (~> 2.4.1)
29
+ public_suffix (4.0.6)
30
+ rainbow (3.0.0)
31
+ rake (13.0.3)
32
+ regexp_parser (2.1.1)
33
+ rexml (3.2.4)
34
+ rspec (3.10.0)
35
+ rspec-core (~> 3.10.0)
36
+ rspec-expectations (~> 3.10.0)
37
+ rspec-mocks (~> 3.10.0)
38
+ rspec-core (3.10.1)
39
+ rspec-support (~> 3.10.0)
40
+ rspec-expectations (3.10.1)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.10.0)
43
+ rspec-mocks (3.10.2)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.10.0)
46
+ rspec-support (3.10.2)
47
+ rubocop (0.93.1)
48
+ parallel (~> 1.10)
49
+ parser (>= 2.7.1.5)
50
+ rainbow (>= 2.2.2, < 4.0)
51
+ regexp_parser (>= 1.8)
52
+ rexml
53
+ rubocop-ast (>= 0.6.0)
54
+ ruby-progressbar (~> 1.7)
55
+ unicode-display_width (>= 1.4.0, < 2.0)
56
+ rubocop-ast (1.4.1)
57
+ parser (>= 2.7.1.5)
58
+ ruby-progressbar (1.11.0)
59
+ ruby2_keywords (0.0.4)
60
+ unicode-display_width (1.7.0)
61
+ vcr (6.0.0)
62
+ webmock (3.12.2)
63
+ addressable (>= 2.3.6)
64
+ crack (>= 0.3.2)
65
+ hashdiff (>= 0.4.0, < 2.0.0)
66
+
67
+ PLATFORMS
68
+ aarch64-linux
69
+ x86_64-linux
70
+
71
+ DEPENDENCIES
72
+ dotenv (~> 2.7)
73
+ fantasticstay_api!
74
+ rake (~> 13.0)
75
+ rspec (~> 3.0)
76
+ rubocop (~> 0.80)
77
+ vcr (~> 6.0)
78
+ webmock (~> 3.12)
79
+
80
+ BUNDLED WITH
81
+ 2.2.33
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 TODO: Write your name
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,43 @@
1
+ # FantasticstayApi
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/fantasticstay_api`. 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 'fantasticstay_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install fantasticstay_api
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 spec` 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]/fantasticstay_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/fantasticstay_api/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the FantasticstayApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/fantasticstay_api/blob/master/CODE_OF_CONDUCT.md).
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,16 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'dotenv/load'
6
+ require 'fantasticstay_api'
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ # require "pry"
13
+ # Pry.start
14
+
15
+ require 'irb'
16
+ 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
@@ -0,0 +1,7 @@
1
+ version: "3.9"
2
+ services:
3
+ app:
4
+ build: .
5
+ command: bash -c "rake"
6
+ volumes:
7
+ - .:/usr/src/app
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/fantasticstay_api/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'fantasticstay_api'
7
+ spec.version = FantasticstayApi::VERSION
8
+ spec.authors = ['Dinis']
9
+ spec.email = ['dinis@lage.pw']
10
+
11
+ spec.summary = 'FantasticStay API Wrapper.'
12
+ spec.description = 'A gem that implements functions from the FS API available for its users.'
13
+ spec.homepage = 'https://github.com/dlage/fantasticstay_api_gem'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
16
+
17
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/dlage/fantasticstay_api_gem'
21
+ spec.metadata['changelog_uri'] = 'https://github.com/dlage/fantasticstay_api_gem/blob/master/CHANGELOG.md'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # spec.add_dependency "example-gem", "~> 1.0"
34
+ spec.add_dependency 'faraday', '~> 1.3.0'
35
+ spec.add_dependency 'oj', '~> 3.11'
36
+ # spec.add_dependency 'dry-configurable', '~> 0.12.1'
37
+
38
+ # For more information and examples about making a new gem, checkout our
39
+ # guide at: https://bundler.io/guides/creating_gem.html
40
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FantasticstayApi
4
+ class API
5
+ class Config
6
+ # Property objects provide an interface for configuration options
7
+ class Property
8
+ attr_reader :name, :default, :required
9
+
10
+ def initialize(name, options)
11
+ @name = name
12
+ @default = options.fetch(:default, nil)
13
+ @required = options.fetch(:required, nil)
14
+ @options = options
15
+ end
16
+
17
+ # @api private
18
+ def define_accessor_methods(properties)
19
+ properties.define_reader_method(self, name, :public)
20
+ properties.define_writer_method(self, "#{name}=", :public)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'set'
4
+
5
+ module FantasticstayApi
6
+ class API
7
+ class Config
8
+ # Class responsible for storing configuration properties
9
+ class PropertySet
10
+ include Enumerable
11
+
12
+ attr_reader :parent, :properties
13
+
14
+ # Initialize an PropertySet
15
+ #
16
+ # @param [Object] parent
17
+ # @param [Set] properties
18
+ #
19
+ # @return [undefined]
20
+ #
21
+ # @api private
22
+ def initialize(parent = nil, properties = Set.new)
23
+ @parent = parent
24
+ @properties = properties
25
+ @map = {}
26
+ end
27
+
28
+ # Iterate over properties
29
+ #
30
+ # @yield [property]
31
+ #
32
+ # @yieldparam [Property] property
33
+ #
34
+ # @return [self]
35
+ #
36
+ # @api public
37
+ def each
38
+ return to_enum unless block_given?
39
+
40
+ @map.each { |name, property| yield property if name.is_a?(Symbol) }
41
+ self
42
+ end
43
+
44
+ # Adds property to the set
45
+ #
46
+ # @example
47
+ # properties_set << property
48
+ #
49
+ # @param [Property] property
50
+ #
51
+ # @return [self]
52
+ #
53
+ # @api public
54
+ def <<(property)
55
+ properties << property
56
+ update_map(property.name, property.default)
57
+ property.define_accessor_methods(self)
58
+ self
59
+ end
60
+
61
+ # Access property by name
62
+ #
63
+ # @api public
64
+ def [](name)
65
+ @map[name]
66
+ end
67
+ alias fetch []
68
+
69
+ # Set property value by name
70
+ #
71
+ # @api public
72
+ def []=(name, property)
73
+ update_map(name, property)
74
+ end
75
+
76
+ # Update map with index
77
+ #
78
+ # @api private
79
+ def update_map(name, property)
80
+ @map[name.to_sym] = @map[name.to_s.freeze] = property
81
+ end
82
+
83
+ # Convert properties to a hash of property names and
84
+ # corresponding values
85
+ #
86
+ # @api public
87
+ def to_hash
88
+ properties.each_with_object({}) do |property, props|
89
+ name = property.name
90
+ props[name] = self[name]
91
+ end
92
+ end
93
+
94
+ # Check if properties exist
95
+ #
96
+ # @api public
97
+ def empty?
98
+ @map.empty?
99
+ end
100
+
101
+ # @api private
102
+ def define_reader_method(property, method_name, visibility)
103
+ property_set = self
104
+ parent.send(:define_method, method_name) { property_set[property.name] }
105
+ parent.send(visibility, method_name)
106
+ end
107
+
108
+ # @api private
109
+ def define_writer_method(property, method_name, visibility)
110
+ property_set = self
111
+ parent.send(:define_method, method_name) do |value|
112
+ property_set[property.name] = value
113
+ end
114
+ parent.send(visibility, method_name)
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'config/property'
4
+ require_relative 'config/property_set'
5
+
6
+ module FantasticstayApi
7
+ class API
8
+ # A base class for constructing api configuration
9
+ class Config
10
+ # Defines a property on an object's class or instance
11
+ #
12
+ # @example
13
+ # class Configuration < Api::Config
14
+ # property :adapter, default: :net_http
15
+ # property :user, required: true
16
+ # end
17
+ #
18
+ # @param [Symbol] name
19
+ # the name of a property
20
+ #
21
+ # @param [#to_hash] options
22
+ # the extra options
23
+ #
24
+ # @return [self]
25
+ #
26
+ # @api public
27
+ def self.property(name, options = {})
28
+ property_set << Property.new(name, options)
29
+ update_subclasses(name, options)
30
+ self
31
+ end
32
+
33
+ def self.update_subclasses(name, options)
34
+ @subclasses.each { |klass| klass.property(name, options) } if defined?(@subclasses) && @subclasses
35
+ end
36
+
37
+ # Check if property is defined
38
+ #
39
+ # @param [Symbol] name
40
+ # the name to check
41
+ #
42
+ # @return [Boolean]
43
+ #
44
+ # @api public
45
+ def self.property?(name)
46
+ property_set.include?(name)
47
+ end
48
+
49
+ class << self
50
+ attr_reader :property_set
51
+ end
52
+
53
+ instance_variable_set('@property_set', PropertySet.new(self))
54
+
55
+ def self.inherited(descendant)
56
+ super
57
+ (@subclasses ||= Set.new) << descendant
58
+ descendant.instance_variable_set(
59
+ '@property_set',
60
+ PropertySet.new(descendant, property_set.properties.dup)
61
+ )
62
+ end
63
+
64
+ def property_names
65
+ self.class.property_set.properties.map(&:name)
66
+ end
67
+
68
+ def self.property_names
69
+ property_set.properties.map(&:name)
70
+ end
71
+
72
+ # Fetch all the properties and their values
73
+ #
74
+ # @return [Hash[Symbol]]
75
+ #
76
+ # @api public
77
+ def fetch(value = nil)
78
+ if value
79
+ self.class.property_set[value]
80
+ else
81
+ self.class.property_set.to_hash
82
+ end
83
+ end
84
+
85
+ # Provide access to properties
86
+ #
87
+ # @example
88
+ # config.call do |config|
89
+ # config.adapter = :net_http
90
+ # end
91
+ #
92
+ # @return [self]
93
+ #
94
+ # @api private
95
+ def call(&block)
96
+ block.call(self) if block_given?
97
+ self
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'api_exceptions'
4
+ require_relative 'configuration'
5
+ require_relative 'constants'
6
+ require_relative 'http_status_codes'
7
+
8
+ module FantasticstayApi
9
+ # Core class responsible for api interface operations
10
+ class API
11
+ include ApiExceptions
12
+ include Constants
13
+ include HttpStatusCodes
14
+
15
+ attr_reader(*FantasticstayApi.configuration.property_names, :token, :endpoint)
16
+
17
+ attr_accessor :current_options
18
+
19
+ # Callback to update current configuration options
20
+ class_eval do
21
+ FantasticstayApi.configuration.property_names.each do |key|
22
+ define_method "#{key}=" do |arg|
23
+ instance_variable_set("@#{key}", arg)
24
+ current_options.merge!({ "#{key}": arg })
25
+ end
26
+ end
27
+ end
28
+
29
+ API_ENDPOINT = 'https://api.fsapp.io'
30
+ HTTP_STATUS_MAPPING = {
31
+ HTTP_BAD_REQUEST_CODE => BadRequestError,
32
+ HTTP_UNAUTHORIZED_CODE => UnauthorizedError,
33
+ HTTP_FORBIDDEN_CODE => ForbiddenError,
34
+ HTTP_NOT_FOUND_CODE => NotFoundError,
35
+ HTTP_UNPROCESSABLE_ENTITY_CODE => UnprocessableEntityError,
36
+ 'default' => ApiError
37
+ }.freeze
38
+
39
+ # Create new API
40
+ #
41
+ # @api public
42
+ def initialize(options = {}, &block)
43
+ opts = FantasticstayApi.configuration.fetch.merge(options)
44
+ @current_options = opts
45
+
46
+ FantasticstayApi.configuration.property_names.each do |key|
47
+ send("#{key}=", opts[key])
48
+ end
49
+ @api_token = opts[:token] || ENV['FANTASTICSTAY_API_TOKEN']
50
+ @api_endpoint = opts[:endpoint] || ENV['FANTASTICSTAY_API_ENDPOINT'] || API_ENDPOINT
51
+
52
+ yield_or_eval(&block) if block_given?
53
+ end
54
+
55
+ # Call block with argument
56
+ #
57
+ # @api private
58
+ def yield_or_eval(&block)
59
+ return unless block
60
+
61
+ block.arity.positive? ? yield(self) : instance_eval(&block)
62
+ end
63
+
64
+ private
65
+
66
+ def client
67
+ # provide your own logger
68
+ logger = Logger.new $stderr
69
+ logger.level = Logger::DEBUG
70
+ @client ||= Faraday.new(@api_endpoint) do |client|
71
+ client.request :url_encoded
72
+ client.adapter Faraday.default_adapter
73
+ client.headers['x-api-key'] = @api_token
74
+ client.response :logger, logger
75
+ end
76
+ end
77
+
78
+ def request(http_method:, endpoint:, params: {})
79
+ response = client.public_send(http_method, endpoint, params)
80
+ parsed_response = Oj.load(response.body)
81
+
82
+ return parsed_response if response_successful?(response)
83
+
84
+ raise error_class(response), "Code: #{response.status}, response: #{response.body}"
85
+ end
86
+
87
+ def error_class(response)
88
+ if HTTP_STATUS_MAPPING.include?(response.status)
89
+ HTTP_STATUS_MAPPING[response.status]
90
+ else
91
+ HTTP_STATUS_MAPPING['default']
92
+ end
93
+ end
94
+
95
+ def response_successful?(response)
96
+ response.status == HTTP_OK_CODE
97
+ end
98
+
99
+ # Responds to attribute query or attribute clear
100
+ #
101
+ # @api private
102
+ def method_missing(method_name, *args, &block)
103
+ # :nodoc:
104
+ case method_name.to_s
105
+ when /^(.*)\?$/
106
+ !!send(Regexp.last_match(1).to_s)
107
+ when /^clear_(.*)$/
108
+ send("#{Regexp.last_match(1)}=", nil)
109
+ else
110
+ super
111
+ end
112
+ end
113
+
114
+ def respond_to_missing?(method_name, include_private = false)
115
+ method_name.to_s.start_with?('clear_') || super
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FantasticstayApi
4
+ module ApiExceptions
5
+ APIExceptionError = Class.new(StandardError)
6
+ BadRequestError = Class.new(APIExceptionError)
7
+ UnauthorizedError = Class.new(APIExceptionError)
8
+ ForbiddenError = Class.new(APIExceptionError)
9
+ ApiRequestsQuotaReachedError = Class.new(APIExceptionError)
10
+ NotFoundError = Class.new(APIExceptionError)
11
+ UnprocessableEntityError = Class.new(APIExceptionError)
12
+ ApiError = Class.new(APIExceptionError)
13
+ end
14
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+ require_relative 'api'
5
+
6
+ module FantasticstayApi
7
+ # Main client class that implements communication with the API
8
+ class Client < API
9
+ def listings
10
+ response = request(
11
+ http_method: :get,
12
+ endpoint: 'listings'
13
+ )
14
+ process_response(response, 'listings')
15
+ end
16
+
17
+ # FantasticstayApi::Client.new.calendar(38859, '2022-01-01', '2022-07-31')
18
+ def calendar(listing_id, start_date = nil, end_date = nil, filters = {})
19
+ response = request(
20
+ http_method: :get,
21
+ endpoint: 'calendar',
22
+ params: {
23
+ listing_id: listing_id,
24
+ start_date: start_date,
25
+ end_date: end_date,
26
+ filters: filters
27
+ }
28
+ )
29
+ process_response(response, 'calendar')
30
+ end
31
+
32
+ # FantasticstayApi::Client.new.reservations(38859)
33
+ def reservations(listing_id, filters = {}, sort = {})
34
+ response = request(
35
+ http_method: :get,
36
+ endpoint: 'reservations',
37
+ params: {
38
+ listing_id: listing_id,
39
+ filters: filters,
40
+ sort: sort
41
+ }
42
+ )
43
+ process_response(response, 'reservations')
44
+ end
45
+
46
+ def reservation(reservation_id, filters = {}, sort = {})
47
+ response = request(
48
+ http_method: :get,
49
+ endpoint: sprintf('reservations/%d', reservation_id)
50
+ )
51
+ process_single(response, 'reservation')
52
+ end
53
+
54
+ def guest(guest_id, filters = {}, sort = {})
55
+ response = request(
56
+ http_method: :get,
57
+ endpoint: sprintf('guests/%d', guest_id)
58
+ )
59
+ process_single(response, 'guest')
60
+ end
61
+
62
+ def integrations
63
+ response = request(
64
+ http_method: :get,
65
+ endpoint: 'integrations'
66
+ )
67
+ process_response(response, 'integrations')
68
+ end
69
+
70
+ protected
71
+
72
+ def process_response(response, model = 'results')
73
+ results = response[model]
74
+ results.each do |r|
75
+ r.transform_keys!(&:to_sym)
76
+ end
77
+ total = response.key?('total') ? response['total'] : 1
78
+ { model.to_sym => results, total: total }
79
+ end
80
+
81
+ def process_single(response, model = 'result')
82
+ result = response[model]
83
+ result.transform_keys!(&:to_sym)
84
+ { model.to_sym => result }
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'api/config'
4
+ require_relative 'version'
5
+
6
+ module FantasticstayApi
7
+ # Stores the configuration
8
+ class Configuration < API::Config
9
+ property :follow_redirects, default: true
10
+
11
+ # The api endpoint used to connect to FantasticstayApi if none is set
12
+ property :endpoint, default: 'https://api.fsapp.io'
13
+
14
+ # The value sent in the http header for 'User-Agent' if none is set
15
+ property :user_agent, default: "FantasticstayApi API Ruby Gem #{FantasticstayApi::VERSION}"
16
+
17
+ # By default uses the Faraday connection options if none is set
18
+ property :connection_options, default: {}
19
+
20
+ # By default display 30 resources
21
+ property :per_page, default: 20
22
+
23
+ # Add Faraday::RackBuilder to overwrite middleware
24
+ property :stack
25
+ end
26
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FantasticstayApi
4
+ # Constants
5
+ module Constants
6
+ # Response headers
7
+ RATELIMIT_REMAINING = 'X-RateLimit-Remaining'
8
+
9
+ RATELIMIT_LIMIT = 'X-RateLimit-Limit'
10
+
11
+ RATELIMIT_RESET = 'X-RateLimit-Reset'
12
+
13
+ CONTENT_TYPE = 'Content-Type'
14
+
15
+ CONTENT_LENGTH = 'content-length'
16
+
17
+ CACHE_CONTROL = 'cache-control'
18
+
19
+ ETAG = 'ETag'
20
+
21
+ SERVER = 'Server'
22
+
23
+ DATE = 'Date'
24
+
25
+ LOCATION = 'Location'
26
+
27
+ USER_AGENT = 'User-Agent'
28
+
29
+ ACCEPT = 'Accept'
30
+
31
+ ACCEPT_CHARSET = 'Accept-Charset'
32
+
33
+ OAUTH_SCOPES = 'X-OAuth-Scopes'
34
+
35
+ ACCEPTED_OAUTH_SCOPES = 'X-Accepted-Oauth-Scopes'
36
+
37
+ # Link headers
38
+ HEADER_LINK = 'Link'
39
+
40
+ HEADER_NEXT = 'X-Next'
41
+
42
+ HEADER_LAST = 'X-Last'
43
+
44
+ META_REL = 'rel'
45
+
46
+ META_LAST = 'last'
47
+
48
+ META_NEXT = 'next'
49
+
50
+ META_FIRST = 'first'
51
+
52
+ META_PREV = 'prev'
53
+
54
+ PARAM_PAGE = 'page'
55
+
56
+ PARAM_PER_PAGE = 'per_page'
57
+
58
+ PARAM_START_PAGE = 'start_page'
59
+
60
+ PARAM_INCLUDE_RELATED = 'include_related_objects'
61
+ end
62
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FantasticstayApi
4
+ module HttpStatusCodes
5
+ HTTP_OK_CODE = 200
6
+
7
+ HTTP_BAD_REQUEST_CODE = 400
8
+ HTTP_UNAUTHORIZED_CODE = 401
9
+ HTTP_FORBIDDEN_CODE = 403
10
+ HTTP_NOT_FOUND_CODE = 404
11
+ HTTP_UNPROCESSABLE_ENTITY_CODE = 429
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FantasticstayApi
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'oj'
5
+ require_relative 'fantasticstay_api/version'
6
+
7
+ module FantasticstayApi
8
+ # Base module for Fantasticstay API
9
+ class Error < StandardError; end
10
+
11
+ LIBNAME = 'fantasticstay_api'
12
+
13
+ LIBDIR = File.expand_path(LIBNAME.to_s, __dir__)
14
+
15
+ class << self
16
+ # The client configuration
17
+ #
18
+ # @return [Configuration]
19
+ #
20
+ # @api public
21
+ def configuration
22
+ @configuration ||= Configuration.new
23
+ end
24
+
25
+ alias config configuration
26
+
27
+ # Configure options
28
+ #
29
+ # @example
30
+ # FantasticstayApi.configure do |c|
31
+ # c.some_option = true
32
+ # end
33
+ #
34
+ # @yield the configuration block
35
+ # @yieldparam configuration [FantasticstayApi::Configuration]
36
+ # the configuration instance
37
+ #
38
+ # @return [nil]
39
+ #
40
+ # @api public
41
+ def configure
42
+ yield configuration
43
+ end
44
+
45
+ # Alias for FantasticstayApi::Client.new
46
+ #
47
+ # @param [Hash] options
48
+ # the configuration options
49
+ #
50
+ # @return [FantasticstayApi::Client]
51
+ #
52
+ # @api public
53
+ def new(options = {}, &block)
54
+ Client.new(options, &block)
55
+ end
56
+
57
+ # Default middleware stack that uses default adapter as specified
58
+ # by configuration setup
59
+ #
60
+ # @return [Proc]
61
+ #
62
+ # @api private
63
+ def default_middleware(options = {})
64
+ Middleware.default(options)
65
+ end
66
+
67
+ # Delegate to FantasticstayApi::Client
68
+ #
69
+ # @api private
70
+ def method_missing(method_name, *args, &block)
71
+ if new.respond_to?(method_name)
72
+ new.send(method_name, *args, &block)
73
+ elsif configuration.respond_to?(method_name)
74
+ FantasticstayApi.configuration.send(method_name, *args, &block)
75
+ else
76
+ super.respond_to_missing?
77
+ end
78
+ end
79
+
80
+ def respond_to_missing?(method_name, include_private = false)
81
+ new.respond_to?(method_name, include_private) ||
82
+ configuration.respond_to?(method_name) ||
83
+ super(method_name, include_private)
84
+ end
85
+ end
86
+ end
87
+
88
+ require_relative 'fantasticstay_api/client'
89
+ require_relative 'fantasticstay_api/configuration'
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fantasticstay_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dinis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: oj
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.11'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.11'
41
+ description: A gem that implements functions from the FS API available for its users.
42
+ email:
43
+ - dinis@lage.pw
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".github/workflows/main.yml"
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".rubocop.yml"
52
+ - CHANGELOG.md
53
+ - CODE_OF_CONDUCT.md
54
+ - Dockerfile
55
+ - Gemfile
56
+ - Gemfile.lock
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - bin/console
61
+ - bin/setup
62
+ - docker-compose.yml
63
+ - fantasticstay_api.gemspec
64
+ - lib/fantasticstay_api.rb
65
+ - lib/fantasticstay_api/api.rb
66
+ - lib/fantasticstay_api/api/config.rb
67
+ - lib/fantasticstay_api/api/config/property.rb
68
+ - lib/fantasticstay_api/api/config/property_set.rb
69
+ - lib/fantasticstay_api/api_exceptions.rb
70
+ - lib/fantasticstay_api/client.rb
71
+ - lib/fantasticstay_api/configuration.rb
72
+ - lib/fantasticstay_api/constants.rb
73
+ - lib/fantasticstay_api/http_status_codes.rb
74
+ - lib/fantasticstay_api/version.rb
75
+ homepage: https://github.com/dlage/fantasticstay_api_gem
76
+ licenses:
77
+ - MIT
78
+ metadata:
79
+ allowed_push_host: https://rubygems.org
80
+ homepage_uri: https://github.com/dlage/fantasticstay_api_gem
81
+ source_code_uri: https://github.com/dlage/fantasticstay_api_gem
82
+ changelog_uri: https://github.com/dlage/fantasticstay_api_gem/blob/master/CHANGELOG.md
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 2.4.0
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubygems_version: 3.3.7
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: FantasticStay API Wrapper.
102
+ test_files: []