fantasticstay_api 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bdecfb00c6c09a2e935ade7f958df01b634928f4c6bb46baa6d6e0992c01ffaa
4
- data.tar.gz: ac032f6927c1b9769224c88008b10c6442c00b0e685b343081e96fd7b651c1f1
3
+ metadata.gz: 34e6c99e07ab528a63116a7bdfcd764a6cd74047f805ef2121c02f82b7266584
4
+ data.tar.gz: 4a2af7516ae2ae8385cf20acb58b282d72d9d52e8024df49f3f3db91fffc32c2
5
5
  SHA512:
6
- metadata.gz: 75c5256ada0d0a1f1b3098ce474820fa6e67a5ca5d997fbab9682be27e745903ea2879dc97797bd940c3f5601c926fe672f053b6adb4b00e8e07bc8657287973
7
- data.tar.gz: 47658f8667df190a20bcb052a6bb2de69fc3b0ad90fb69c08777a6f47e2fa1e906bb5431ef349cb81a2ebf57d856bb6b523ef5d7bb916eff74030b2fd2d4d4b0
6
+ metadata.gz: 8be0b2d3027bdf240d35414d4800dfaaf13de5e2c06348dac2c7fbbf38670f362829b29ff898b4cd1c82ee34d17034c9b6ed686ebdaad735f5eabb235487da80
7
+ data.tar.gz: dced4169e85772446ba7441ea95da1d32f96f8e76d37aaa1a87b1c4aa72193c78a8d0f64334086505a3869050e48a8fc7f0ad85795ff08697d22747bb6e1156a
data/Dockerfile CHANGED
@@ -2,7 +2,11 @@ FROM ruby:3.0
2
2
 
3
3
  WORKDIR /usr/src/app
4
4
 
5
- COPY . .
5
+ COPY Gemfile .
6
+ COPY Gemfile.lock .
7
+ COPY fantasticstay_api.gemspec .
8
+ COPY lib/fantasticstay_api/version.rb lib/fantasticstay_api/version.rb
6
9
 
7
10
  RUN bundle install
8
11
 
12
+ COPY . .
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # FantasticstayApi
2
2
 
3
+ ![main workflow](https://github.com/dlage/fantasticstay_api_gem/actions/workflows/main.yml/badge.svg)
4
+
3
5
  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
6
 
5
7
  TODO: Delete this and the text above, and describe your gem
data/Rakefile CHANGED
@@ -3,7 +3,9 @@
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rspec/core/rake_task'
5
5
 
6
- RSpec::Core::RakeTask.new(:spec)
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ end
7
9
 
8
10
  require 'rubocop/rake_task'
9
11
 
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.license = 'MIT'
15
15
  spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
16
16
 
17
- spec.metadata['allowed_push_host'] = "https://rubygems.org"
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
18
 
19
19
  spec.metadata['homepage_uri'] = spec.homepage
20
20
  spec.metadata['source_code_uri'] = 'https://github.com/dlage/fantasticstay_api_gem'
@@ -31,9 +31,9 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  # Uncomment to register a new dependency of your gem
33
33
  # spec.add_dependency "example-gem", "~> 1.0"
34
+ spec.add_dependency 'api_cache', '~> 0.3.0'
34
35
  spec.add_dependency 'faraday', '~> 1.3.0'
35
36
  spec.add_dependency 'oj', '~> 3.11'
36
- spec.add_dependency 'api_cache', '~> 0.3.0'
37
37
 
38
38
  # spec.add_dependency 'dry-configurable', '~> 0.12.1'
39
39
 
@@ -14,7 +14,7 @@ module FantasticstayApi
14
14
  include Constants
15
15
  include HttpStatusCodes
16
16
 
17
- attr_reader(*FantasticstayApi.configuration.property_names, :token, :endpoint)
17
+ attr_reader(*FantasticstayApi.configuration.property_names)
18
18
 
19
19
  attr_accessor :current_options
20
20
 
@@ -28,7 +28,6 @@ module FantasticstayApi
28
28
  end
29
29
  end
30
30
 
31
- API_ENDPOINT = 'https://api.fsapp.io'
32
31
  HTTP_STATUS_MAPPING = {
33
32
  HTTP_BAD_REQUEST_CODE => BadRequestError,
34
33
  HTTP_UNAUTHORIZED_CODE => UnauthorizedError,
@@ -48,8 +47,6 @@ module FantasticstayApi
48
47
  FantasticstayApi.configuration.property_names.each do |key|
49
48
  send("#{key}=", opts[key])
50
49
  end
51
- @api_token = opts[:token] || ENV['FANTASTICSTAY_API_TOKEN']
52
- @api_endpoint = opts[:endpoint] || ENV['FANTASTICSTAY_API_ENDPOINT'] || API_ENDPOINT
53
50
 
54
51
  yield_or_eval(&block) if block_given?
55
52
  end
@@ -69,18 +66,22 @@ module FantasticstayApi
69
66
  # provide your own logger
70
67
  logger = Logger.new $stderr
71
68
  logger.level = Logger::DEBUG
72
- @client ||= Faraday.new(@api_endpoint) do |client|
69
+ @client ||= Faraday.new(@endpoint) do |client|
73
70
  client.request :url_encoded
74
71
  client.adapter Faraday.default_adapter
75
72
  client.headers['Content-Type'] = 'application/json'
76
- client.headers['x-api-key'] = @api_token
73
+ client.headers['x-api-key'] = @token
74
+ client.headers['User-Agent'] = @user_agent
77
75
  client.response :logger, logger
78
76
  end
79
77
  end
80
78
 
81
79
  def request(http_method:, endpoint:, params: {}, cache_ttl: 3600)
82
- response = APICache.get(Digest::SHA256.bubblebabble(@api_token) + http_method.to_s + endpoint + params.to_s, cache: cache_ttl) do
83
- client.public_send(http_method, endpoint, params)
80
+ response = APICache.get(
81
+ Digest::SHA256.bubblebabble(@token) + http_method.to_s + endpoint + params.to_s,
82
+ cache: cache_ttl
83
+ ) do
84
+ client.public_send(http_method, endpoint, params)
84
85
  end
85
86
  parsed_response = Oj.load(response.body)
86
87
 
@@ -108,7 +109,7 @@ module FantasticstayApi
108
109
  # :nodoc:
109
110
  case method_name.to_s
110
111
  when /^(.*)\?$/
111
- !!send(Regexp.last_match(1).to_s)
112
+ !send(Regexp.last_match(1).to_s).nil?
112
113
  when /^clear_(.*)$/
113
114
  send("#{Regexp.last_match(1)}=", nil)
114
115
  else
@@ -26,10 +26,7 @@ module FantasticstayApi
26
26
  http_method: :get,
27
27
  endpoint: 'calendar',
28
28
  params: {
29
- listing_id: listing_id,
30
- start_date: start_date,
31
- end_date: end_date,
32
- filters: filters.to_json
29
+ listing_id: listing_id, start_date: start_date, end_date: end_date, filters: filters.to_json
33
30
  }.merge(global_params)
34
31
  )
35
32
  process_response(response)
@@ -45,16 +42,14 @@ module FantasticstayApi
45
42
  end
46
43
 
47
44
  # FantasticstayApi::Client.new.reservations(38859)
48
- def reservations(listing_id, filters = [], sort = nil, global_params = {})
45
+ def reservations(listing_id, filters = [], sort = { order: 'checkIn', direction: 'desc' }, global_params = {})
49
46
  response = request(
50
47
  http_method: :get,
51
48
  endpoint: 'reservations',
52
49
  params: {
53
- listing_id: listing_id,
54
- filters: filters.to_json,
55
- sort: sort
50
+ listing_id: listing_id, filters: filters.to_json, sort: sort[:order], direction: sort[:direction]
56
51
  }.merge!(global_params),
57
- cache_ttl: 3600*24
52
+ cache_ttl: 3600 * 24
58
53
  )
59
54
  process_response(response)
60
55
  end
@@ -73,7 +68,7 @@ module FantasticstayApi
73
68
  http_method: :get,
74
69
  endpoint: "guests/#{guest_id}",
75
70
  params: global_params,
76
- cache_ttl: 3600*24
71
+ cache_ttl: 3600 * 24
77
72
  )
78
73
  process_response(response)
79
74
  end
@@ -94,13 +89,9 @@ module FantasticstayApi
94
89
  case result
95
90
  when Hash
96
91
  result.transform_keys!(&:to_sym)
97
- result.values.each do |r|
98
- process_response(r)
99
- end
92
+ result.each_value { |r| process_response(r) }
100
93
  when Array
101
- result.each do |r|
102
- process_response(r)
103
- end
94
+ result.each { |r| process_response(r) }
104
95
  end
105
96
  result
106
97
  end
@@ -6,19 +6,25 @@ require_relative 'version'
6
6
  module FantasticstayApi
7
7
  # Stores the configuration
8
8
  class Configuration < API::Config
9
+ API_ENDPOINT = 'https://api.fsapp.io'
10
+ API_TOKEN = 'TESTING'
11
+
9
12
  property :follow_redirects, default: true
10
13
 
11
14
  # The api endpoint used to connect to FantasticstayApi if none is set
12
- property :endpoint, default: 'https://api.fsapp.io/'
15
+ property :endpoint, default: ENV['FANTASTICSTAY_API_ENDPOINT'] || API_ENDPOINT
16
+
17
+ # The token included in request header 'x-api-key'
18
+ property :token, default: ENV['FANTASTICSTAY_API_TOKEN'] || API_TOKEN
13
19
 
14
20
  # 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}"
21
+ property :user_agent, default: "FantasticstayApi API Ruby Gem #{FantasticstayApi::VERSION}"
16
22
 
17
23
  # By default uses the Faraday connection options if none is set
18
- property :connection_options, default: {}
24
+ property :connection_options, default: {}
19
25
 
20
26
  # By default display 30 resources
21
- property :per_page, default: 20
27
+ property :per_page, default: 10
22
28
 
23
29
  # Add Faraday::RackBuilder to overwrite middleware
24
30
  property :stack
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FantasticstayApi
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.3'
5
5
  end
@@ -4,8 +4,8 @@ require 'faraday'
4
4
  require 'oj'
5
5
  require_relative 'fantasticstay_api/version'
6
6
 
7
+ # Base module for Fantasticstay API
7
8
  module FantasticstayApi
8
- # Base module for Fantasticstay API
9
9
  class Error < StandardError; end
10
10
 
11
11
  LIBNAME = 'fantasticstay_api'
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fantasticstay_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dinis
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-14 00:00:00.000000000 Z
11
+ date: 2022-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: faraday
14
+ name: api_cache
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.3.0
19
+ version: 0.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.3.0
26
+ version: 0.3.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: oj
28
+ name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.11'
33
+ version: 1.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.11'
40
+ version: 1.3.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: api_cache
42
+ name: oj
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.3.0
47
+ version: '3.11'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.3.0
54
+ version: '3.11'
55
55
  description: A gem that implements functions from the FS API available for its users.
56
56
  email:
57
57
  - dinis@lage.pw
@@ -94,7 +94,7 @@ metadata:
94
94
  homepage_uri: https://github.com/dlage/fantasticstay_api_gem
95
95
  source_code_uri: https://github.com/dlage/fantasticstay_api_gem
96
96
  changelog_uri: https://github.com/dlage/fantasticstay_api_gem/blob/master/CHANGELOG.md
97
- post_install_message:
97
+ post_install_message:
98
98
  rdoc_options: []
99
99
  require_paths:
100
100
  - lib
@@ -109,8 +109,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  requirements: []
112
- rubygems_version: 3.3.7
113
- signing_key:
112
+ rubygems_version: 3.2.33
113
+ signing_key:
114
114
  specification_version: 4
115
115
  summary: FantasticStay API Wrapper.
116
116
  test_files: []