guesty_api 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db90ac9f82e97c490061fd47ee316953d3fe43997ee5ffa9f165df18b1259d8d
4
- data.tar.gz: c5cc6cad1089f44af83e3ca276299d4013662524eb9ac159089d968e1617e8a5
3
+ metadata.gz: 39438afe33293a237144661141fe8645be196f4db3dd04331079d17c11ec8dd6
4
+ data.tar.gz: b76baaf5b6a0ccc79cc5cfb20d77152533729bea0ff529ffab3271c6f6072f8a
5
5
  SHA512:
6
- metadata.gz: 801e187c99420f7d208c16f65ca30a1558f36a3b8e306d50b3a1779717d9d86a8fc73ae2b66f60f04008866a4f0076f334fb56538aab327f758a573fe301d8c1
7
- data.tar.gz: c42601333ee2c62a85ed961534ba4203130ebfe3a378da076c258039285a478c418dc46df5f4a13848c41238250c3891ea1054539c41fd3c894ef22d0216bcdf
6
+ metadata.gz: 5bdad0e9c799c457796cd5b86a508b98971bbf057aca4c912ff26a84354aa68dba591d8e6e113ac12b5f54e1be7314e6ded6a0f1d6c0178394dd25f35d00fa07
7
+ data.tar.gz: 2a5dac364beb4b5164f371425403566b0a1ef47d7f582e1cf44f3edf97433b8203e3b23a71f6bd32e8970d79396ad9af5bcef50a4ed08ba0614d50b1074481dd
@@ -28,18 +28,3 @@ jobs:
28
28
  - run: bundle install
29
29
  - name: Run tests
30
30
  run: bundle exec rake
31
- - name: Release Gem
32
-
33
- release:
34
- runs-on: ubuntu-latest
35
-
36
- steps:
37
- - uses: actions/checkout@v2
38
-
39
- - name: Release Gem
40
- if: contains(github.ref, 'refs/tags/v')
41
- uses: cadwallion/publish-rubygems-action@master
42
- env:
43
- GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
44
- RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
45
- RELEASE_COMMAND: rake release
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
- --require spec_helper
2
+ --format documentation
3
+ --require spec_helper
@@ -1,14 +1,107 @@
1
- example_id | status | run_time |
2
- ------------------------------------------- | ------ | --------------- |
3
- ./spec/guesty_api/accounts_spec.rb[1:1:1:1] | passed | 0.01021 seconds |
4
- ./spec/guesty_api/accounts_spec.rb[1:1:2:1] | passed | 0.00111 seconds |
5
- ./spec/guesty_api/accounts_spec.rb[1:1:2:2] | passed | 0.00119 seconds |
6
- ./spec/guesty_api/client_spec.rb[1:1:1:1] | passed | 0.00611 seconds |
7
- ./spec/guesty_api/client_spec.rb[1:1:2:1] | passed | 0.00019 seconds |
8
- ./spec/guesty_api/client_spec.rb[1:1:3:1] | passed | 0.00068 seconds |
9
- ./spec/guesty_api/client_spec.rb[1:1:4:1] | passed | 0.00016 seconds |
10
- ./spec/guesty_api/client_spec.rb[1:2:1:1] | passed | 0.00021 seconds |
11
- ./spec/guesty_api/client_spec.rb[1:2:2:1] | passed | 0.0006 seconds |
12
- ./spec/guesty_api/client_spec.rb[1:2:3:1] | passed | 0.00016 seconds |
13
- ./spec/guesty_api/client_spec.rb[1:2:4:1] | passed | 0.00016 seconds |
14
- ./spec/guesty_api_spec.rb[1:1] | passed | 0.00098 seconds |
1
+ example_id | status | run_time |
2
+ ------------------------------------------------- | ------ | --------------- |
3
+ ./spec/guesty_api/accounts_spec.rb[1:1:1:1:1] | passed | 0.00972 seconds |
4
+ ./spec/guesty_api/accounts_spec.rb[1:1:2:1] | passed | 0.00117 seconds |
5
+ ./spec/guesty_api/accounts_spec.rb[1:1:2:2] | passed | 0.00106 seconds |
6
+ ./spec/guesty_api/client_spec.rb[1:1:1:1] | passed | 0.0033 seconds |
7
+ ./spec/guesty_api/client_spec.rb[1:1:2:1] | passed | 0.00019 seconds |
8
+ ./spec/guesty_api/client_spec.rb[1:1:3:1] | passed | 0.01063 seconds |
9
+ ./spec/guesty_api/client_spec.rb[1:1:4:1] | passed | 0.00019 seconds |
10
+ ./spec/guesty_api/client_spec.rb[1:2:1:1] | passed | 0.00017 seconds |
11
+ ./spec/guesty_api/client_spec.rb[1:2:2:1] | passed | 0.00017 seconds |
12
+ ./spec/guesty_api/client_spec.rb[1:2:3:1] | passed | 0.00024 seconds |
13
+ ./spec/guesty_api/client_spec.rb[1:2:4:1] | passed | 0.0002 seconds |
14
+ ./spec/guesty_api/guest_inbox_spec.rb[1:1:1:1:1] | passed | 0.00161 seconds |
15
+ ./spec/guesty_api/guest_inbox_spec.rb[1:1:2:1] | passed | 0.00133 seconds |
16
+ ./spec/guesty_api/guest_inbox_spec.rb[1:2:1:1:1] | passed | 0.00164 seconds |
17
+ ./spec/guesty_api/guest_inbox_spec.rb[1:2:2:1] | passed | 0.00388 seconds |
18
+ ./spec/guesty_api/guest_inbox_spec.rb[1:2:3:1] | passed | 0.00354 seconds |
19
+ ./spec/guesty_api/guest_inbox_spec.rb[1:2:3:2] | passed | 0.00254 seconds |
20
+ ./spec/guesty_api/guest_inbox_spec.rb[1:3:1:1:1] | passed | 0.00125 seconds |
21
+ ./spec/guesty_api/guest_inbox_spec.rb[1:3:2:1] | passed | 0.00078 seconds |
22
+ ./spec/guesty_api/guest_inbox_spec.rb[1:3:3:1:1] | passed | 0.00139 seconds |
23
+ ./spec/guesty_api/guest_inbox_spec.rb[1:3:3:2:1] | passed | 0.00267 seconds |
24
+ ./spec/guesty_api/guest_inbox_spec.rb[1:3:3:2:2] | passed | 0.00739 seconds |
25
+ ./spec/guesty_api/guests_spec.rb[1:1:1:1:1] | passed | 0.00352 seconds |
26
+ ./spec/guesty_api/guests_spec.rb[1:1:2:1] | passed | 0.00141 seconds |
27
+ ./spec/guesty_api/guests_spec.rb[1:2:1:1:1] | passed | 0.0086 seconds |
28
+ ./spec/guesty_api/guests_spec.rb[1:2:2:1] | passed | 0.00276 seconds |
29
+ ./spec/guesty_api/guests_spec.rb[1:2:3:1] | passed | 0.00239 seconds |
30
+ ./spec/guesty_api/guests_spec.rb[1:2:3:2] | passed | 0.00119 seconds |
31
+ ./spec/guesty_api/guests_spec.rb[1:3:1:1:1] | passed | 0.0012 seconds |
32
+ ./spec/guesty_api/guests_spec.rb[1:3:2:1:1] | passed | 0.00101 seconds |
33
+ ./spec/guesty_api/guests_spec.rb[1:3:2:2:1] | passed | 0.0051 seconds |
34
+ ./spec/guesty_api/guests_spec.rb[1:3:2:2:2] | passed | 0.01053 seconds |
35
+ ./spec/guesty_api/guests_spec.rb[1:4:1:1:1] | passed | 0.00189 seconds |
36
+ ./spec/guesty_api/guests_spec.rb[1:4:2:1] | passed | 0.00624 seconds |
37
+ ./spec/guesty_api/guests_spec.rb[1:4:3:1:1] | passed | 0.00158 seconds |
38
+ ./spec/guesty_api/guests_spec.rb[1:4:3:1:2] | passed | 0.00106 seconds |
39
+ ./spec/guesty_api/guests_spec.rb[1:5:1:1:1] | passed | 0.00132 seconds |
40
+ ./spec/guesty_api/guests_spec.rb[1:5:2:1] | passed | 0.00078 seconds |
41
+ ./spec/guesty_api/guests_spec.rb[1:5:3:1] | passed | 0.00108 seconds |
42
+ ./spec/guesty_api/listings_spec.rb[1:1:1:1:1] | passed | 0.0012 seconds |
43
+ ./spec/guesty_api/listings_spec.rb[1:1:2:1] | passed | 0.00102 seconds |
44
+ ./spec/guesty_api/listings_spec.rb[1:2:1:1:1] | passed | 0.00691 seconds |
45
+ ./spec/guesty_api/listings_spec.rb[1:2:2:1] | passed | 0.00148 seconds |
46
+ ./spec/guesty_api/listings_spec.rb[1:2:3:1] | passed | 0.00106 seconds |
47
+ ./spec/guesty_api/listings_spec.rb[1:2:3:2] | passed | 0.00091 seconds |
48
+ ./spec/guesty_api/listings_spec.rb[1:3:1:1:1] | passed | 0.00089 seconds |
49
+ ./spec/guesty_api/listings_spec.rb[1:3:2:1:1] | passed | 0.0008 seconds |
50
+ ./spec/guesty_api/listings_spec.rb[1:3:2:2:1] | passed | 0.00085 seconds |
51
+ ./spec/guesty_api/listings_spec.rb[1:3:2:2:2] | passed | 0.00081 seconds |
52
+ ./spec/guesty_api/listings_spec.rb[1:4:1:1:1] | passed | 0.00129 seconds |
53
+ ./spec/guesty_api/listings_spec.rb[1:4:2:1] | passed | 0.00354 seconds |
54
+ ./spec/guesty_api/listings_spec.rb[1:4:3:1:1] | passed | 0.00212 seconds |
55
+ ./spec/guesty_api/listings_spec.rb[1:4:3:2:1] | passed | 0.00141 seconds |
56
+ ./spec/guesty_api/listings_spec.rb[1:4:3:2:2] | passed | 0.00407 seconds |
57
+ ./spec/guesty_api/reservations_spec.rb[1:1:1:1:1] | passed | 0.00145 seconds |
58
+ ./spec/guesty_api/reservations_spec.rb[1:1:2:1] | passed | 0.0008 seconds |
59
+ ./spec/guesty_api/reservations_spec.rb[1:2:1:1:1] | passed | 0.00626 seconds |
60
+ ./spec/guesty_api/reservations_spec.rb[1:2:2:1] | passed | 0.00281 seconds |
61
+ ./spec/guesty_api/reservations_spec.rb[1:2:3:1] | passed | 0.00123 seconds |
62
+ ./spec/guesty_api/reservations_spec.rb[1:2:3:2] | passed | 0.00101 seconds |
63
+ ./spec/guesty_api/reservations_spec.rb[1:3:1:1:1] | passed | 0.00098 seconds |
64
+ ./spec/guesty_api/reservations_spec.rb[1:3:2:1:1] | passed | 0.00078 seconds |
65
+ ./spec/guesty_api/reservations_spec.rb[1:3:2:2:1] | passed | 0.00096 seconds |
66
+ ./spec/guesty_api/reservations_spec.rb[1:3:2:2:2] | passed | 0.0009 seconds |
67
+ ./spec/guesty_api/reservations_spec.rb[1:4:1:1:1] | passed | 0.00263 seconds |
68
+ ./spec/guesty_api/reservations_spec.rb[1:4:2:1] | passed | 0.00264 seconds |
69
+ ./spec/guesty_api/reservations_spec.rb[1:4:3:1:1] | passed | 0.00133 seconds |
70
+ ./spec/guesty_api/reservations_spec.rb[1:4:3:2:1] | passed | 0.00116 seconds |
71
+ ./spec/guesty_api/reservations_spec.rb[1:4:3:2:2] | passed | 0.00126 seconds |
72
+ ./spec/guesty_api/users_spec.rb[1:1:1:1:1] | passed | 0.00117 seconds |
73
+ ./spec/guesty_api/users_spec.rb[1:1:2:1] | passed | 0.00076 seconds |
74
+ ./spec/guesty_api/users_spec.rb[1:2:1:1:1] | passed | 0.00145 seconds |
75
+ ./spec/guesty_api/users_spec.rb[1:2:2:1] | passed | 0.00087 seconds |
76
+ ./spec/guesty_api/users_spec.rb[1:2:3:1] | passed | 0.01038 seconds |
77
+ ./spec/guesty_api/users_spec.rb[1:2:3:2] | passed | 0.00146 seconds |
78
+ ./spec/guesty_api/users_spec.rb[1:3:1:1:1] | passed | 0.00103 seconds |
79
+ ./spec/guesty_api/users_spec.rb[1:3:2:1:1] | passed | 0.00074 seconds |
80
+ ./spec/guesty_api/users_spec.rb[1:3:2:2:1] | passed | 0.00088 seconds |
81
+ ./spec/guesty_api/users_spec.rb[1:3:2:2:2] | passed | 0.00084 seconds |
82
+ ./spec/guesty_api/users_spec.rb[1:4:1:1:1] | passed | 0.0013 seconds |
83
+ ./spec/guesty_api/users_spec.rb[1:4:2:1] | passed | 0.00082 seconds |
84
+ ./spec/guesty_api/users_spec.rb[1:4:3:1:1] | passed | 0.00354 seconds |
85
+ ./spec/guesty_api/users_spec.rb[1:4:3:2:1] | passed | 0.00172 seconds |
86
+ ./spec/guesty_api/users_spec.rb[1:4:3:2:2] | passed | 0.00191 seconds |
87
+ ./spec/guesty_api/users_spec.rb[1:5:1:1:1] | passed | 0.00097 seconds |
88
+ ./spec/guesty_api/users_spec.rb[1:5:2:1] | passed | 0.0009 seconds |
89
+ ./spec/guesty_api/users_spec.rb[1:5:3:1] | passed | 0.00082 seconds |
90
+ ./spec/guesty_api/webhooks_spec.rb[1:1:1:1:1] | passed | 0.00129 seconds |
91
+ ./spec/guesty_api/webhooks_spec.rb[1:1:2:1] | passed | 0.00109 seconds |
92
+ ./spec/guesty_api/webhooks_spec.rb[1:2:1:1:1] | passed | 0.00141 seconds |
93
+ ./spec/guesty_api/webhooks_spec.rb[1:2:2:1] | passed | 0.00077 seconds |
94
+ ./spec/guesty_api/webhooks_spec.rb[1:2:3:1] | passed | 0.0039 seconds |
95
+ ./spec/guesty_api/webhooks_spec.rb[1:2:3:2] | passed | 0.00286 seconds |
96
+ ./spec/guesty_api/webhooks_spec.rb[1:3:1:1:1] | passed | 0.00154 seconds |
97
+ ./spec/guesty_api/webhooks_spec.rb[1:3:2:1:1] | passed | 0.00131 seconds |
98
+ ./spec/guesty_api/webhooks_spec.rb[1:3:2:2:1] | passed | 0.0009 seconds |
99
+ ./spec/guesty_api/webhooks_spec.rb[1:3:2:2:2] | passed | 0.00073 seconds |
100
+ ./spec/guesty_api/webhooks_spec.rb[1:4:1:1:1] | passed | 0.00419 seconds |
101
+ ./spec/guesty_api/webhooks_spec.rb[1:4:2:1] | passed | 0.00092 seconds |
102
+ ./spec/guesty_api/webhooks_spec.rb[1:4:3:1:1] | passed | 0.00118 seconds |
103
+ ./spec/guesty_api/webhooks_spec.rb[1:4:3:2:1] | passed | 0.00463 seconds |
104
+ ./spec/guesty_api/webhooks_spec.rb[1:5:1:1:1] | passed | 0.0012 seconds |
105
+ ./spec/guesty_api/webhooks_spec.rb[1:5:2:1] | passed | 0.00078 seconds |
106
+ ./spec/guesty_api/webhooks_spec.rb[1:5:3:1] | passed | 0.00073 seconds |
107
+ ./spec/guesty_api_spec.rb[1:1] | passed | 0.00006 seconds |
@@ -56,17 +56,8 @@ RSpec/ContextWording:
56
56
  RSpec/MessageSpies:
57
57
  EnforcedStyle: receive
58
58
 
59
- RSpec/DescribeClass:
60
- Exclude:
61
- - spec/requests/**/*
62
-
63
59
  RSpec/NamedSubject:
64
60
  Enabled: false
65
61
 
66
- RSpec/RepeatedExample:
67
- Exclude:
68
- - spec/policies/**/*
69
-
70
- RSpec/MultipleExpectations:
71
- Exclude:
72
- - spec/mailers/**/*
62
+ RSpec/NestedGroups:
63
+ Max: 5
@@ -0,0 +1,33 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [Unreleased]
6
+
7
+ ## [0.2.0] - 2020-08-02
8
+
9
+ ### Added
10
+
11
+ - Ability to operate on Guesty's Users: list, retrieve, create, update, delete
12
+ - Ability to operate on Guesty's Listings: list, retrieve, create, update, delete
13
+ - Ability to operate on Guesty's Reservations: list, retrieve, create, update, delete
14
+ - Ability to operate on Guesty's Guests: list, retrieve, create, update, delete
15
+ - Ability to operate on Guesty's Guests Inbox: list, retrieve, post messages
16
+
17
+ ### Changed
18
+
19
+ - Adjusted error handling
20
+ - Introduced collection/single entity responses methods to simplify maintability
21
+
22
+ ## [0.1.0] - 2020-07-27
23
+
24
+ ### Added
25
+
26
+ - Default Guesty API client
27
+ - Ability to retrieve account
28
+ - This CHANGELOG file to hopefully serve as an evolving example of a
29
+ standardized open source project CHANGELOG.
30
+ - Basic README file.
31
+ - GitHub Actions
32
+
33
+ [0.1.0]: https://github.com/mihilbabin/guesty_api/releases/tag/v0.1.0
@@ -1,9 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- guesty_api (0.1.0)
4
+ guesty_api (0.2.0)
5
5
  httparty (~> 0.17.0)
6
- oj (~> 3.7)
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
@@ -23,7 +22,6 @@ GEM
23
22
  mime-types-data (~> 3.2015)
24
23
  mime-types-data (3.2020.0512)
25
24
  multi_xml (0.6.0)
26
- oj (3.10.8)
27
25
  parallel (1.19.2)
28
26
  parser (2.7.1.4)
29
27
  ast (~> 2.4.1)
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # GuestyAPI
2
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/guesty_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
3
+ Simple wrapper on top of [Guesty API](https://docs.guesty.com/)
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,17 +20,11 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
23
+ Check [wiki](https://github.com/mihilbabin/guesty_api/wiki) for usage and more.
32
24
 
33
25
  ## Contributing
34
26
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/guesty_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]/guesty_api/blob/master/CODE_OF_CONDUCT.md).
27
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mihilbabin/guesty_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/mihilbabin/guesty_api/blob/master/CODE_OF_CONDUCT.md).
36
28
 
37
29
  ## License
38
30
 
@@ -40,4 +32,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
40
32
 
41
33
  ## Code of Conduct
42
34
 
43
- Everyone interacting in the GuestyAPI project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/guesty_api/blob/master/CODE_OF_CONDUCT.md).
35
+ Everyone interacting in the GuestyAPI project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mihilbabin/guesty_api/blob/master/CODE_OF_CONDUCT.md).
@@ -37,5 +37,4 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency 'webmock', '~> 3.8', '>= 3.8.3'
38
38
 
39
39
  spec.add_dependency 'httparty', '~> 0.17.0'
40
- spec.add_dependency 'oj', '~> 3.7'
41
40
  end
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'httparty'
4
- require 'oj'
5
-
6
3
  require 'guesty_api/resource_base'
7
4
  require 'guesty_api/accounts'
8
5
  require 'guesty_api/client'
9
6
  require 'guesty_api/entities'
7
+ require 'guesty_api/guests'
8
+ require 'guesty_api/guest_inbox'
9
+ require 'guesty_api/listings'
10
+ require 'guesty_api/reservations'
11
+ require 'guesty_api/users'
12
+ require 'guesty_api/webhooks'
10
13
  require 'guesty_api/version'
11
14
 
12
15
  module GuestyAPI
@@ -5,9 +5,15 @@ module GuestyAPI
5
5
  def retrieve
6
6
  response = @client.get url: '/accounts/me'
7
7
 
8
- throw!(body: response.body, code: response.code) unless response.success?
8
+ check_response! response
9
9
 
10
- Entities::Account.new(parsed_body(response))
10
+ single_entity response
11
+ end
12
+
13
+ private
14
+
15
+ def entity_class
16
+ Entities::Account
11
17
  end
12
18
  end
13
19
  end
@@ -1,9 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'httparty'
4
+
3
5
  module GuestyAPI
4
6
  class Client
5
7
  include HTTParty
6
8
  base_uri 'https://api.guesty.com/api/v2'
9
+ headers 'Content-Type' => 'application/json'
7
10
 
8
11
  def initialize(username:, password: nil, auth_mode: :basic)
9
12
  @username = username
@@ -16,11 +19,11 @@ module GuestyAPI
16
19
  end
17
20
 
18
21
  def post(url:, data:)
19
- self.class.post(url, body: data, **auth)
22
+ self.class.post(url, body: data.to_json, **auth)
20
23
  end
21
24
 
22
25
  def put(url:, data:)
23
- self.class.put(url, body: data, **auth)
26
+ self.class.put(url, body: data.to_json, **auth)
24
27
  end
25
28
 
26
29
  def delete(url:)
@@ -2,3 +2,9 @@
2
2
 
3
3
  require 'guesty_api/entities/base'
4
4
  require 'guesty_api/entities/account'
5
+ require 'guesty_api/entities/guest'
6
+ require 'guesty_api/entities/guest_conversation'
7
+ require 'guesty_api/entities/listing'
8
+ require 'guesty_api/entities/reservation'
9
+ require 'guesty_api/entities/user'
10
+ require 'guesty_api/entities/webhook'
@@ -14,7 +14,7 @@ module GuestyAPI
14
14
  end
15
15
 
16
16
  def respond_to_missing?(_method_name, _include_private = false)
17
- true
17
+ @methods.include? method
18
18
  end
19
19
  end
20
20
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GuestyAPI
4
+ module Entities
5
+ class Guest < Base; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GuestyAPI
4
+ module Entities
5
+ class GuestConversation < Base; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GuestyAPI
4
+ module Entities
5
+ class Listing < Base; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GuestyAPI
4
+ module Entities
5
+ class Reservation < Base; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GuestyAPI
4
+ module Entities
5
+ class User < Base; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GuestyAPI
4
+ module Entities
5
+ class Webhook < Base; end
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GuestyAPI
4
+ class GuestInbox < ResourceBase
5
+ def list(params: {})
6
+ response = @client.get url: '/inbox/conversations', data: params
7
+
8
+ check_response! response
9
+
10
+ collection_entity response
11
+ end
12
+
13
+ def retrieve(id:, fields: nil)
14
+ response = @client.get url: "/inbox/conversations/#{id}", data: { fields: fields }
15
+
16
+ check_response! response
17
+
18
+ single_entity response
19
+ end
20
+
21
+ def post(id:, params:)
22
+ response = @client.post url: '/inbox/conversations', data: {
23
+ conversationId: id,
24
+ }.merge(params)
25
+
26
+ check_response! response
27
+
28
+ single_entity response
29
+ end
30
+
31
+ private
32
+
33
+ def entity_class
34
+ Entities::GuestConversation
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GuestyAPI
4
+ class Guests < ResourceBase
5
+ def list(params: {})
6
+ response = @client.get(
7
+ url: '/guests',
8
+ data: params,
9
+ )
10
+ check_response! response
11
+
12
+ collection_entity response
13
+ end
14
+
15
+ def retrieve(id:, fields: nil)
16
+ response = @client.get url: "/guests/#{id}", data: { fields: fields }
17
+
18
+ check_response! response
19
+
20
+ single_entity response
21
+ end
22
+
23
+ def create(params:)
24
+ response = @client.post url: '/guests', data: params
25
+
26
+ check_response! response
27
+
28
+ single_entity response
29
+ end
30
+
31
+ def update(id:, params:)
32
+ response = @client.put url: "/guests/#{id}", data: params
33
+
34
+ check_response! response
35
+
36
+ single_entity response
37
+ end
38
+
39
+ def delete(id:)
40
+ response = @client.delete url: "/guests/#{id}"
41
+
42
+ check_response! response
43
+
44
+ true
45
+ end
46
+
47
+ private
48
+
49
+ def entity_class
50
+ Entities::Guest
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GuestyAPI
4
+ class Listings < ResourceBase
5
+ def list(params: {})
6
+ response = @client.get url: '/listings', data: params
7
+
8
+ check_response! response
9
+
10
+ collection_entity response
11
+ end
12
+
13
+ def retrieve(id:, fields: nil)
14
+ response = @client.get url: "/listings/#{id}", data: { fields: fields }
15
+
16
+ check_response! response
17
+
18
+ single_entity response
19
+ end
20
+
21
+ def create(params:)
22
+ response = @client.post url: '/listings', data: params
23
+
24
+ check_response! response
25
+
26
+ single_entity response
27
+ end
28
+
29
+ def update(id:, params:)
30
+ response = @client.put url: "/listings/#{id}", data: params
31
+
32
+ check_response! response
33
+
34
+ single_entity response
35
+ end
36
+
37
+ private
38
+
39
+ def entity_class
40
+ Entities::Listing
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GuestyAPI
4
+ class Reservations < ResourceBase
5
+ def list(params: {})
6
+ response = @client.get url: '/reservations', data: params
7
+
8
+ check_response! response
9
+
10
+ collection_entity response
11
+ end
12
+
13
+ def retrieve(id:, fields: nil)
14
+ response = @client.get url: "/reservations/#{id}", data: { fields: fields }
15
+
16
+ check_response! response
17
+
18
+ single_entity response
19
+ end
20
+
21
+ def create(params:)
22
+ response = @client.post url: '/reservations', data: params
23
+
24
+ check_response! response
25
+
26
+ single_entity response
27
+ end
28
+
29
+ def update(id:, params:)
30
+ response = @client.put url: "/reservations/#{id}", data: params
31
+
32
+ check_response! response
33
+
34
+ single_entity response
35
+ end
36
+
37
+ private
38
+
39
+ def entity_class
40
+ Entities::Reservation
41
+ end
42
+ end
43
+ end
@@ -8,12 +8,27 @@ module GuestyAPI
8
8
 
9
9
  private
10
10
 
11
- def parsed_body(response)
12
- JSON.parse response.body
11
+ def entity_class
12
+ raise StandardError, '`:entity_class method` should be overriden in a subclass'
13
13
  end
14
14
 
15
- def throw!(body:, code:)
16
- raise APIError.new(body, code)
15
+ def check_response!(response)
16
+ parsed = response.parsed_response
17
+ msg = parsed.is_a?(Hash) ? parsed['message'] || parsed.dig('error', 'message') : parsed
18
+
19
+ throw!(msg: msg, code: response.code) unless response.success?
20
+ end
21
+
22
+ def single_entity(response)
23
+ entity_class.new response.parsed_response
24
+ end
25
+
26
+ def collection_entity(response)
27
+ response.parsed_response['results'].map { |payload| entity_class.new payload }
28
+ end
29
+
30
+ def throw!(msg:, code:)
31
+ raise APIError.new(msg, code)
17
32
  end
18
33
  end
19
34
  end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GuestyAPI
4
+ class Users < ResourceBase
5
+ def list(params: {})
6
+ response = @client.get(
7
+ url: '/users',
8
+ data: params,
9
+ )
10
+ check_response! response
11
+
12
+ collection_entity response
13
+ end
14
+
15
+ def retrieve(id: :me, fields: nil)
16
+ url = id == :me ? '/me' : "/users/#{id}"
17
+ response = @client.get url: url, data: { fields: fields }
18
+
19
+ check_response! response
20
+
21
+ single_entity response
22
+ end
23
+
24
+ def create(params:)
25
+ response = @client.post url: '/users', data: params
26
+
27
+ check_response! response
28
+
29
+ single_entity response
30
+ end
31
+
32
+ def update(id: :me, params:)
33
+ url = id == :me ? '/me' : "/users/#{id}"
34
+ response = @client.put url: url, data: params
35
+
36
+ check_response! response
37
+
38
+ single_entity response
39
+ end
40
+
41
+ def delete(id:)
42
+ response = @client.delete url: "/users/#{id}"
43
+
44
+ check_response! response
45
+
46
+ true
47
+ end
48
+
49
+ private
50
+
51
+ def entity_class
52
+ Entities::User
53
+ end
54
+ end
55
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GuestyAPI
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GuestyAPI
4
+ class Webhooks < ResourceBase
5
+ def list
6
+ response = @client.get url: '/webhooks'
7
+
8
+ check_response! response
9
+
10
+ response.parsed_response.map { |payload| entity_class.new payload }
11
+ end
12
+
13
+ def retrieve(id:)
14
+ response = @client.get url: "/webhooks/#{id}"
15
+
16
+ check_response! response
17
+
18
+ single_entity response
19
+ end
20
+
21
+ def create(params:)
22
+ response = @client.post url: '/webhooks', data: params
23
+
24
+ check_response! response
25
+
26
+ single_entity response
27
+ end
28
+
29
+ def update(id:, params:)
30
+ response = @client.put url: "/webhooks/#{id}", data: params
31
+
32
+ check_response! response
33
+
34
+ true
35
+ end
36
+
37
+ def delete(id:)
38
+ response = @client.delete url: "/webhooks/#{id}"
39
+
40
+ check_response! response
41
+
42
+ true
43
+ end
44
+
45
+ private
46
+
47
+ def entity_class
48
+ Entities::Webhook
49
+ end
50
+ end
51
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guesty_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Babin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-27 00:00:00.000000000 Z
11
+ date: 2020-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -120,20 +120,6 @@ dependencies:
120
120
  - - "~>"
121
121
  - !ruby/object:Gem::Version
122
122
  version: 0.17.0
123
- - !ruby/object:Gem::Dependency
124
- name: oj
125
- requirement: !ruby/object:Gem::Requirement
126
- requirements:
127
- - - "~>"
128
- - !ruby/object:Gem::Version
129
- version: '3.7'
130
- type: :runtime
131
- prerelease: false
132
- version_requirements: !ruby/object:Gem::Requirement
133
- requirements:
134
- - - "~>"
135
- - !ruby/object:Gem::Version
136
- version: '3.7'
137
123
  description: Simple abstractions for Guesty API
138
124
  email:
139
125
  - iamsuperman@ukr.net
@@ -147,6 +133,7 @@ files:
147
133
  - ".rspec"
148
134
  - ".rspec_status"
149
135
  - ".rubocop.yml"
136
+ - CHANGELOG.md
150
137
  - CODE_OF_CONDUCT.md
151
138
  - Gemfile
152
139
  - Gemfile.lock
@@ -162,8 +149,20 @@ files:
162
149
  - lib/guesty_api/entities.rb
163
150
  - lib/guesty_api/entities/account.rb
164
151
  - lib/guesty_api/entities/base.rb
152
+ - lib/guesty_api/entities/guest.rb
153
+ - lib/guesty_api/entities/guest_conversation.rb
154
+ - lib/guesty_api/entities/listing.rb
155
+ - lib/guesty_api/entities/reservation.rb
156
+ - lib/guesty_api/entities/user.rb
157
+ - lib/guesty_api/entities/webhook.rb
158
+ - lib/guesty_api/guest_inbox.rb
159
+ - lib/guesty_api/guests.rb
160
+ - lib/guesty_api/listings.rb
161
+ - lib/guesty_api/reservations.rb
165
162
  - lib/guesty_api/resource_base.rb
163
+ - lib/guesty_api/users.rb
166
164
  - lib/guesty_api/version.rb
165
+ - lib/guesty_api/webhooks.rb
167
166
  homepage: https://github.com/mihilbabin/guesty_api
168
167
  licenses:
169
168
  - MIT