airbnb_api 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gemrelease +3 -0
- data/README.md +3 -0
- data/lib/airbnb_api.rb +5 -0
- data/lib/airbnb_api/api_operations/find.rb +1 -1
- data/lib/airbnb_api/client.rb +6 -2
- data/lib/airbnb_api/errors/errors.rb +4 -0
- data/lib/airbnb_api/resource.rb +28 -4
- data/lib/airbnb_api/resource/listing.rb +1 -1
- data/lib/airbnb_api/resource/message.rb +16 -0
- data/lib/airbnb_api/resource/thread.rb +14 -0
- data/lib/airbnb_api/resource/token.rb +1 -1
- data/lib/airbnb_api/service.rb +6 -2
- data/lib/airbnb_api/service/thread.rb +18 -0
- data/lib/airbnb_api/service/token.rb +0 -1
- data/lib/airbnb_api/util/error_handling.rb +3 -3
- data/lib/airbnb_api/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae64494c7f4748668a3547f158e86571bd26a17a594a36e93d644dff23033740
|
4
|
+
data.tar.gz: 3d5dd25d97ca2d732c3b1d77fd267305fcca0750b455e915a19ccab8ebb9db10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bae5da378e1e3e5ff364d506694d6209fcea16fa26065900ef56eded77fe1fe008742a29b126b09c34d302b9e0ea7cace0ba0548d9ecfe34ef9ba66606b9c8b0
|
7
|
+
data.tar.gz: e4304c98e6d398568edd398d636bc17bac46482d07a3c35075df9f0ced620c65a176aca6bc6359e4deafc08d50f8e47b4e2e4b3d87d275fd1c69c9f57b1a3b83
|
data/.gemrelease
ADDED
data/README.md
CHANGED
@@ -4,6 +4,9 @@
|
|
4
4
|
|
5
5
|
The AirbnbApi ruby library provides an easy way to interact with the Airbnb API. The Airbnb API is being actively developed so please expect this gem to change regularly. The documentation for the Airbnb API can be found [here](https://www.airbnb.com/partner/api-docs/).
|
6
6
|
|
7
|
+
**Please note**
|
8
|
+
This gem is very much work in progress and not yet intended for public use.
|
9
|
+
|
7
10
|
## Installation
|
8
11
|
|
9
12
|
Add this line to your application's Gemfile:
|
data/lib/airbnb_api.rb
CHANGED
@@ -13,10 +13,15 @@ require 'airbnb_api/client'
|
|
13
13
|
require 'airbnb_api/service'
|
14
14
|
require 'airbnb_api/service/listing'
|
15
15
|
require 'airbnb_api/service/token'
|
16
|
+
require 'airbnb_api/service/thread'
|
17
|
+
|
16
18
|
|
17
19
|
require 'airbnb_api/resource'
|
18
20
|
require 'airbnb_api/resource/listing'
|
19
21
|
require 'airbnb_api/resource/token'
|
22
|
+
require 'airbnb_api/resource/message'
|
23
|
+
require 'airbnb_api/resource/thread'
|
24
|
+
|
20
25
|
|
21
26
|
require 'airbnb_api/errors/errors'
|
22
27
|
require 'airbnb_api/util/error_handling'
|
data/lib/airbnb_api/client.rb
CHANGED
@@ -3,7 +3,7 @@ require 'base64'
|
|
3
3
|
module AirbnbApi
|
4
4
|
class Client
|
5
5
|
attr_reader :id, :secret, :oauth_token
|
6
|
-
def initialize(id:, secret
|
6
|
+
def initialize(id:, secret: nil, oauth_token: nil)
|
7
7
|
@id = id
|
8
8
|
@secret = secret
|
9
9
|
@oauth_token = oauth_token
|
@@ -35,7 +35,11 @@ module AirbnbApi
|
|
35
35
|
|
36
36
|
%i[get patch post delete].each do |call|
|
37
37
|
define_method call do |path, options = {}|
|
38
|
-
|
38
|
+
begin
|
39
|
+
http.public_send(call, "#{version}#{path}", options).body
|
40
|
+
rescue Faraday::ConnectionFailed => err
|
41
|
+
raise AirbnbApi::Errors::Timeout, err
|
42
|
+
end
|
39
43
|
end
|
40
44
|
end
|
41
45
|
|
data/lib/airbnb_api/resource.rb
CHANGED
@@ -1,13 +1,21 @@
|
|
1
1
|
module AirbnbApi
|
2
2
|
module Resource
|
3
3
|
def initialize(attributes)
|
4
|
-
self.attributes = attributes
|
4
|
+
self.attributes = self.class.root_element ? attributes.dig(self.class.root_element) : attributes
|
5
5
|
end
|
6
6
|
|
7
|
+
private
|
8
|
+
|
7
9
|
def attributes=(attributes)
|
8
10
|
@attributes = attributes
|
11
|
+
|
9
12
|
attributes.each do |attribute, value|
|
10
|
-
if
|
13
|
+
if self.class.many && self.class.many.has_key?(attribute.to_sym)
|
14
|
+
items = value.map do |data|
|
15
|
+
self.class.many[attribute.to_sym].new(data)
|
16
|
+
end
|
17
|
+
send(attribute.to_s + '=', items)
|
18
|
+
elsif respond_to?(writer = attribute.to_s + '=')
|
11
19
|
send(writer, value)
|
12
20
|
else
|
13
21
|
# self.class.logger.warn "`#{attribute}' is not a listed attribute for #{self.class}"
|
@@ -16,12 +24,28 @@ module AirbnbApi
|
|
16
24
|
end
|
17
25
|
|
18
26
|
module ClassMethods
|
19
|
-
attr_reader :attributes
|
20
27
|
|
21
|
-
|
28
|
+
attr_reader :attributes, :many, :root
|
29
|
+
|
30
|
+
def has_attributes(attributes)
|
22
31
|
attr_accessor(*@attributes = attributes)
|
23
32
|
end
|
24
33
|
|
34
|
+
def has_many(attribute, klass)
|
35
|
+
@many ||= {}
|
36
|
+
@many[attribute.to_sym] = klass
|
37
|
+
attr_accessor(attribute.to_sym)
|
38
|
+
end
|
39
|
+
|
40
|
+
def has_root(boolean)
|
41
|
+
@root = boolean
|
42
|
+
end
|
43
|
+
|
44
|
+
def root_element
|
45
|
+
@root = @root.nil? ? true : @root
|
46
|
+
@root ? name.to_s.gsub(/([^\^])([A-Z])/,'\1_\2').downcase.to_sym : nil
|
47
|
+
end
|
48
|
+
|
25
49
|
def build(attributes)
|
26
50
|
new(attributes)
|
27
51
|
end
|
data/lib/airbnb_api/service.rb
CHANGED
@@ -9,12 +9,17 @@ module AirbnbApi
|
|
9
9
|
end
|
10
10
|
|
11
11
|
module ClassMethods
|
12
|
-
attr_accessor :path
|
12
|
+
attr_accessor :path, :parameters
|
13
13
|
attr_reader :requires_oauth_token
|
14
14
|
def set_path(path)
|
15
15
|
@path = path
|
16
16
|
end
|
17
17
|
|
18
|
+
def set_parameter(parameter, default)
|
19
|
+
@parameters ||= {}
|
20
|
+
@parameters[parameter.to_sym] = default
|
21
|
+
end
|
22
|
+
|
18
23
|
def require_oauth_token
|
19
24
|
@requires_oauth_token = true
|
20
25
|
end
|
@@ -26,7 +31,6 @@ module AirbnbApi
|
|
26
31
|
def requires_oauth_token?
|
27
32
|
@requires_oauth_token == true
|
28
33
|
end
|
29
|
-
|
30
34
|
end
|
31
35
|
end
|
32
36
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module AirbnbApi
|
2
|
+
module Service
|
3
|
+
class Thread
|
4
|
+
include AirbnbApi::Service
|
5
|
+
extend AirbnbApi::Service::ClassMethods
|
6
|
+
include AirbnbApi::APIOperations::Find
|
7
|
+
|
8
|
+
set_path '/threads'
|
9
|
+
set_parameter :_format, 'for_api_partners'
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def resource_class
|
14
|
+
AirbnbApi::Resource::Thread
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -7,11 +7,11 @@ module AirbnbApi
|
|
7
7
|
402 => true,
|
8
8
|
403 => true,
|
9
9
|
404 => true,
|
10
|
-
405 =>
|
10
|
+
405 => AirbnbApi::Errors::RateLimit,
|
11
11
|
406 => true,
|
12
12
|
422 => true,
|
13
|
-
429 =>
|
14
|
-
|
13
|
+
429 => AirbnbApi::Errors::RateLimit,
|
14
|
+
503 => AirbnbApi::Errors::RateLimit
|
15
15
|
}.freeze
|
16
16
|
|
17
17
|
def on_complete(response)
|
data/lib/airbnb_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: airbnb_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dennis van der Vliet
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -115,6 +115,7 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
+
- ".gemrelease"
|
118
119
|
- ".gitignore"
|
119
120
|
- ".rspec"
|
120
121
|
- ".travis.yml"
|
@@ -133,9 +134,12 @@ files:
|
|
133
134
|
- lib/airbnb_api/errors/errors.rb
|
134
135
|
- lib/airbnb_api/resource.rb
|
135
136
|
- lib/airbnb_api/resource/listing.rb
|
137
|
+
- lib/airbnb_api/resource/message.rb
|
138
|
+
- lib/airbnb_api/resource/thread.rb
|
136
139
|
- lib/airbnb_api/resource/token.rb
|
137
140
|
- lib/airbnb_api/service.rb
|
138
141
|
- lib/airbnb_api/service/listing.rb
|
142
|
+
- lib/airbnb_api/service/thread.rb
|
139
143
|
- lib/airbnb_api/service/token.rb
|
140
144
|
- lib/airbnb_api/util/error_handling.rb
|
141
145
|
- lib/airbnb_api/version.rb
|