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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0262d0d2c4edc76ce9cb77e5b308e260fb49e9e63fcf797d482e2c0a59c0f850
4
- data.tar.gz: b64ac5cdda817cb1783605c2ee928d564f2d482ed1a41125ceb71d6401b7aa74
3
+ metadata.gz: ae64494c7f4748668a3547f158e86571bd26a17a594a36e93d644dff23033740
4
+ data.tar.gz: 3d5dd25d97ca2d732c3b1d77fd267305fcca0750b455e915a19ccab8ebb9db10
5
5
  SHA512:
6
- metadata.gz: 9b4b6dba5958956b7a59686127531a42a8cf143986d20378447d3bb6928497ae5be0d6a5a576f3ada00c3717f4af3573fd9baa1bd1ca19f619c82c4e8f24825a
7
- data.tar.gz: 1b0a4b655b32ec733390abc79183f3f1c1429c0128e0127672de392808cc4d71dbdeb2440c5128887ccf14b9e9f9b49bb8c1675a5b0548badfdfd76d184c9bbc
6
+ metadata.gz: bae5da378e1e3e5ff364d506694d6209fcea16fa26065900ef56eded77fe1fe008742a29b126b09c34d302b9e0ea7cace0ba0548d9ecfe34ef9ba66606b9c8b0
7
+ data.tar.gz: e4304c98e6d398568edd398d636bc17bac46482d07a3c35075df9f0ced620c65a176aca6bc6359e4deafc08d50f8e47b4e2e4b3d87d275fd1c69c9f57b1a3b83
@@ -0,0 +1,3 @@
1
+ bump:
2
+ push: true
3
+ tag: true
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:
@@ -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'
@@ -2,7 +2,7 @@ module AirbnbApi
2
2
  module APIOperations
3
3
  module Find
4
4
  def find(id)
5
- @client.get("#{self.class.path}/#{id}")
5
+ build @client.get("#{self.class.path}/#{id}", self.class.parameters)
6
6
  end
7
7
  end
8
8
  end
@@ -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:, oauth_token: nil)
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
- http.public_send(call, "#{version}#{path}", options).body
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
 
@@ -2,7 +2,11 @@ module AirbnbApi
2
2
  module Errors
3
3
  class BadRequest < StandardError
4
4
  end
5
+ class RateLimit < StandardError
6
+ end
5
7
  class InvalidClient < StandardError
6
8
  end
9
+ class Timeout < StandardError
10
+ end
7
11
  end
8
12
  end
@@ -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 respond_to?(writer = attribute.to_s + '=')
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
- def attributes(attributes)
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
@@ -4,7 +4,7 @@ module AirbnbApi
4
4
  include AirbnbApi::Resource
5
5
  extend AirbnbApi::Resource::ClassMethods
6
6
 
7
- attributes %i[
7
+ has_attributes %i[
8
8
  id
9
9
  name
10
10
  property_type_category
@@ -0,0 +1,16 @@
1
+ module AirbnbApi
2
+ module Resource
3
+ class Message
4
+ include AirbnbApi::Resource
5
+ extend AirbnbApi::Resource::ClassMethods
6
+
7
+ has_attributes %i[
8
+ id
9
+ message
10
+ created_at
11
+ attachment_images
12
+ user_id
13
+ ]
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module AirbnbApi
2
+ module Resource
3
+ class Thread
4
+ include AirbnbApi::Resource
5
+ extend AirbnbApi::Resource::ClassMethods
6
+
7
+ has_attributes %i[
8
+ thread
9
+ ]
10
+
11
+ has_many :messages, AirbnbApi::Resource::Message
12
+ end
13
+ end
14
+ end
@@ -4,7 +4,7 @@ module AirbnbApi
4
4
  include AirbnbApi::Resource
5
5
  extend AirbnbApi::Resource::ClassMethods
6
6
 
7
- attributes %i[
7
+ has_attributes %i[
8
8
  access_token
9
9
  expires_at
10
10
  refresh_token
@@ -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
@@ -2,7 +2,6 @@ module AirbnbApi
2
2
  module Service
3
3
  class Token
4
4
  include AirbnbApi::Service
5
- include AirbnbApi::APIOperations::Create
6
5
  include AirbnbApi::APIOperations::Find
7
6
  extend AirbnbApi::Service::ClassMethods
8
7
 
@@ -7,11 +7,11 @@ module AirbnbApi
7
7
  402 => true,
8
8
  403 => true,
9
9
  404 => true,
10
- 405 => true,
10
+ 405 => AirbnbApi::Errors::RateLimit,
11
11
  406 => true,
12
12
  422 => true,
13
- 429 => true,
14
- 500 => true
13
+ 429 => AirbnbApi::Errors::RateLimit,
14
+ 503 => AirbnbApi::Errors::RateLimit
15
15
  }.freeze
16
16
 
17
17
  def on_complete(response)
@@ -1,3 +1,3 @@
1
1
  module AirbnbApi
2
- VERSION = '0.2.5'.freeze
2
+ VERSION = '0.2.6'.freeze
3
3
  end
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.5
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-02 00:00:00.000000000 Z
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