bookingsync-api 0.0.1

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
+ SHA1:
3
+ metadata.gz: e7a7b6ab1a172640a5ad5e01dca78d0aae5694b8
4
+ data.tar.gz: a0cfcfe2429857f95e36cf6f3690e3611c88bbb3
5
+ SHA512:
6
+ metadata.gz: 904395f6a792621c69c12ccfc2059710af400bab9ebc681b3226e3e67d3c9f89cb3c77f31fce52d49e2838c89793e3537164e5bfd372c93f9d762e30a3a0f40e
7
+ data.tar.gz: efec160c80837d94c52a9aef2aeee9a95f54106a7ea8b73fe43ba9aa517037ac0f7fb85f326861b4b82dd16564322478bfec50a1722751f6e7360b2e620f3e89
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.0.0
5
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bookingsync-api.gemspec
4
+
5
+ group 'test' do
6
+ gem 'rspec', '3.0.0.beta2'
7
+ gem 'vcr'
8
+ gem 'webmock'
9
+ gem 'guard'
10
+ gem 'guard-rspec'
11
+ gem 'yard'
12
+ end
13
+
14
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,6 @@
1
+ guard :rspec do
2
+ watch(%r{^lib/bookingsync/(.+)\.rb$}) { |m| "spec/bookingsync/#{m[1]}_spec.rb" }
3
+ watch(%r{^lib/bookingsync/api/client/(.+)\.rb$}) { |m| "spec/bookingsync/api/client/#{m[1]}_spec.rb" }
4
+ watch(%r{^lib/bookingsync/api/(.+)\.rb$}) { |m| "spec/bookingsync/api/#{m[1]}_spec.rb" }
5
+ watch('spec/spec_helper.rb') { "spec" }
6
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2014 Sébastien Grosjean and BookingSync.com
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ [![Build Status](https://travis-ci.org/BookingSync/bookingsync-api.png?branch=master)](https://travis-ci.org/BookingSync/bookingsync-api)
2
+ [![Code Climate](https://codeclimate.com/github/BookingSync/bookingsync-api.png)](https://codeclimate.com/github/BookingSync/bookingsync-api)
3
+
4
+ # BookingSync::API
5
+
6
+ This gem allows Ruby developers to programmatically access https://www.bookingsync.com
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'bookingsync-api'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install bookingsync-api
21
+
22
+ ## Usage
23
+
24
+ Gem assumes that you already have OAuth token for an account.
25
+
26
+ api = BookingSync::API.new("OAUTH_TOKEN")
27
+ rentals = api.rentals # => [Sawyer::Resource, Sawyer::Resource]
28
+ rentals.first.name # => "Small apartment"
29
+
30
+ See our [documentation](http://rubydoc.info/github/BookingSync/bookingsync-api) for more info.
31
+
32
+ ## Running specs
33
+
34
+ bundle exec rspec
35
+
36
+ OR
37
+
38
+ bundle exec guard
39
+
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( http://github.com/BookingSync/bookingsync-api/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ task :default => :spec
4
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bookingsync/api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bookingsync-api"
8
+ spec.version = BookingSync::API::VERSION
9
+ spec.authors = ["Sébastien Grosjean"]
10
+ spec.email = ["dev@bookingsync.com"]
11
+ spec.summary = %q{Ruby interface for accessing https://www.bookingsync.com}
12
+ spec.description = %q{This gem allows to interact with the BookingSync API via Ruby objects}
13
+ spec.homepage = "https://github.com/BookingSync/bookingsync-api"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "faraday", "~> 0.9"
22
+ spec.add_dependency "sawyer"
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,17 @@
1
+ require "faraday"
2
+ require "sawyer"
3
+
4
+ require "bookingsync/api/version"
5
+ require "bookingsync/api/client"
6
+
7
+ module BookingSync
8
+ module API
9
+ # Return new API Client
10
+ #
11
+ # @param token [String] OAuth token
12
+ # @return [BookingSync::API::Client] New BookingSync API client
13
+ def self.new(token)
14
+ Client.new(token)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,106 @@
1
+ require "bookingsync/api/middleware/authentication"
2
+ require "bookingsync/api/client/bookings"
3
+ require "bookingsync/api/client/rentals"
4
+ require "bookingsync/api/error"
5
+
6
+ module BookingSync::API
7
+ class Client
8
+ include BookingSync::API::Client::Bookings
9
+ include BookingSync::API::Client::Rentals
10
+
11
+ MEDIA_TYPE = "application/vnd.api+json"
12
+
13
+ attr_reader :token
14
+
15
+ # Initialize new Client
16
+ #
17
+ # @param token [String] OAuth token
18
+ # @return [BookingSync::API::Client] New BookingSync API client
19
+ def initialize(token)
20
+ @token = token
21
+ end
22
+
23
+ # Make a HTTP GET request
24
+ #
25
+ # @param path [String] The path, relative to {#api_endpoint}
26
+ # @return [Array<Sawyer::Resource>] Array of resources.
27
+ def get(path, options = {})
28
+ request :get, path, options
29
+ end
30
+
31
+ # Return API endpoint
32
+ #
33
+ # @return [String] URL to API endpoint
34
+ def api_endpoint
35
+ "#{base_url}/api/v3"
36
+ end
37
+
38
+ protected
39
+
40
+ # Make a HTTP request to given path
41
+ #
42
+ # @param method [Symbol] HTTP verb to use.
43
+ # @param path [String] The path, relative to {#api_endpoint}.
44
+ # @param options [Hash] A customizable set of options.
45
+ # @option options [Array] fields: List of fields to be fetched.
46
+ # @return [Array<Sawyer::Resource>] Array of resources.
47
+ def request(method, path, options = {})
48
+ request_options = {}
49
+ if options.has_key?(:fields)
50
+ fields = Array(options[:fields]).join(",")
51
+ request_options[:query] = {fields: fields}
52
+ end
53
+
54
+ response = agent.call(method, path, nil, request_options)
55
+ case response.status
56
+ # fetch objects from outer hash
57
+ # {rentals => [{rental}, {rental}]}
58
+ # will return [{rental}, {rental}]
59
+ when 200..299; response.data.to_hash.values.flatten
60
+ when 401; raise Unauthorized.new
61
+ end
62
+ end
63
+
64
+ private
65
+
66
+ def agent
67
+ @agent ||= Sawyer::Agent.new(api_endpoint, sawyer_options) do |http|
68
+ http.headers[:accept] = MEDIA_TYPE
69
+ end
70
+ end
71
+
72
+ def middleware
73
+ Faraday::RackBuilder.new do |builder|
74
+ builder.use :authentication, token
75
+ builder.adapter Faraday.default_adapter
76
+ end
77
+ end
78
+
79
+ def sawyer_options
80
+ {faraday: Faraday.new(faraday_options)}
81
+ end
82
+
83
+ def faraday_options
84
+ {builder: middleware, ssl: {verify: verify_ssl?}}
85
+ end
86
+
87
+ # Return BookingSync base URL. Default is https://www.bookingsync.com
88
+ # it can be altered via ENV variable BOOKINGSYNC_URL which
89
+ # is useful in specs when recording vcr cassettes
90
+ #
91
+ # @return [String] Base URL to BookingSync
92
+ def base_url
93
+ ENV.fetch "BOOKINGSYNC_URL", "https://www.bookingsync.com"
94
+ end
95
+
96
+ # Return true if SSL cert should be verified
97
+ # By default is true, can be changed to false using
98
+ # env variable VERIFY_SSL
99
+ #
100
+ # @return [Boolean] true if SSL needs to be verified
101
+ # false otherwise
102
+ def verify_ssl?
103
+ ENV["BOOKINGSYNC_VERIFY_SSL"] == "false" ? false : true
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,16 @@
1
+ module BookingSync::API
2
+ class Client
3
+ module Bookings
4
+ # List bookings
5
+ #
6
+ # Return public future bookings for the account user
7
+ # is authenticated with.
8
+ # @param options [Hash] A customizable set of options.
9
+ # @option options [Array] fields: List of fields to be fetched.
10
+ # @return [Array<Sawyer::Resource>] Array of bookings.
11
+ def bookings(options = {})
12
+ get :bookings, options
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ module BookingSync::API
2
+ class Client
3
+ module Rentals
4
+ # List rentals
5
+ #
6
+ # Returns rentals for the account user is authenticated with.
7
+ # @param options [Hash] A customizable set of options.
8
+ # @option options [Array] fields: List of fields to be fetched.
9
+ # @return [Array<Sawyer::Resource>] Array of rentals.
10
+ #
11
+ # @example Get the list of rentals for the current account
12
+ # rentals = @api.rentals
13
+ # rentals.first.name # => "Small apartment"
14
+ # @example Get the list of rentals only with name and description for smaller response
15
+ # @api.rentals(fields: [:name, :description])
16
+ def rentals(options = {})
17
+ get :rentals, options
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ module BookingSync::API
2
+ # Class for rescuing all BS API errors
3
+ class Error < StandardError; end
4
+ class Unauthorized < Error; end
5
+ end
@@ -0,0 +1,18 @@
1
+ module BookingSync::API::Middleware
2
+ # Provides faraday middleware for authentication using OAuth token
3
+ # We don't use default FaradayMiddleware::OAuth2 because
4
+ # it adds access_token param to the URL
5
+ class Authentication < Faraday::Middleware
6
+ def initialize(app, token)
7
+ @app = app
8
+ @token = token
9
+ end
10
+
11
+ def call(env)
12
+ env[:request_headers]["Authorization"] = "Bearer #{@token}"
13
+ @app.call(env)
14
+ end
15
+ end
16
+
17
+ Faraday::Middleware.register_middleware authentication: Authentication
18
+ end
@@ -0,0 +1,5 @@
1
+ module BookingSync
2
+ module API
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe BookingSync::API::Client::Bookings do
4
+ let(:client) { BookingSync::API::Client.new(test_access_token) }
5
+
6
+ describe ".bookings", :vcr do
7
+ it "returns bookings" do
8
+ expect(client.bookings).not_to be_nil
9
+ assert_requested :get, bs_url("bookings")
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ describe BookingSync::API::Client::Rentals do
4
+ let(:client) { BookingSync::API::Client.new(test_access_token) }
5
+
6
+ describe ".rentals", :vcr do
7
+ it "returns rentals" do
8
+ expect(client.rentals).not_to be_nil
9
+ assert_requested :get, bs_url("rentals")
10
+ end
11
+
12
+ context "with specified fields in options" do
13
+ it "returns rentals with filtered fields" do
14
+ rentals = client.rentals(fields: :name)
15
+ expect(rentals).not_to be_nil
16
+ assert_requested :get, bs_url("rentals?fields=name")
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,84 @@
1
+ require "spec_helper"
2
+
3
+ describe BookingSync::API::Client do
4
+ let(:client) { BookingSync::API::Client.new(test_access_token) }
5
+
6
+ describe "#new" do
7
+ it "initializes client object with given token" do
8
+ client = BookingSync::API::Client.new("xyz")
9
+ expect(client.token).to eql("xyz")
10
+ end
11
+ end
12
+
13
+ describe "#get" do
14
+ before { VCR.turn_off! }
15
+ it "makes a HTTP GET request" do
16
+ stub_get("resource")
17
+ client.get("resource")
18
+ assert_requested :get, bs_url("resource")
19
+ end
20
+ end
21
+
22
+ describe "#request" do
23
+ before { VCR.turn_off! }
24
+ it "authenticates the request with OAuth token" do
25
+ ENV["ACCESS_TOKEN"] = nil
26
+ stub_get("resource")
27
+ client.get("resource")
28
+ assert_requested :get, bs_url("resource"),
29
+ headers: {"Authorization" => "Bearer fake-access-token"}
30
+ end
31
+
32
+ it "requests proper content type for JSON API" do
33
+ stub_get("resource")
34
+ client.get("resource")
35
+ assert_requested :get, bs_url("resource"),
36
+ headers: {"Accept" => "application/vnd.api+json"}
37
+ end
38
+
39
+ it "returns Array of resources" do
40
+ stub_get("resource", body: {resources: [{name: "Megan"}]}.to_json)
41
+ resources = client.get("resource")
42
+ expect(resources.size).to eq(1)
43
+ expect(resources.first.name).to eq("Megan")
44
+ end
45
+
46
+ context "client returns 401" do
47
+ it "raises Unauthorized exception" do
48
+ stub_get("resource", status: 401)
49
+ expect {
50
+ client.get("resource")
51
+ }.to raise_error(BookingSync::API::Unauthorized)
52
+ end
53
+ end
54
+
55
+ context "status code is outside 200..299 range" do
56
+ it "returns nil" do
57
+ stub_get("resource", status: 404)
58
+ expect(client.get("resource")).to be_nil
59
+ end
60
+ end
61
+
62
+ context "user wants to fetch only specific fields" do
63
+ it "constructs url for filtered fields" do
64
+ stub_get("resource?fields=name,description")
65
+ client.get("resource", fields: [:name, :description])
66
+ assert_requested :get, bs_url("resource?fields=name,description")
67
+ end
68
+ end
69
+ end
70
+
71
+ describe "#api_endpoint" do
72
+ it "returns URL to the API" do
73
+ ENV["BOOKINGSYNC_URL"] = nil
74
+ expect(client.api_endpoint).to eql("https://www.bookingsync.com/api/v3")
75
+ end
76
+
77
+ context "user specifies base URL via BOOKINGSYNC_URL env" do
78
+ it "returns custom URL to the API" do
79
+ ENV["BOOKINGSYNC_URL"] = "https://bookingsync.dev"
80
+ expect(client.api_endpoint).to eql("https://bookingsync.dev/api/v3")
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ describe BookingSync::API do
4
+ it "should have a version number" do
5
+ expect(BookingSync::API::VERSION).not_to be_nil
6
+ end
7
+
8
+ describe ".new" do
9
+ it "returns a new Client" do
10
+ client = BookingSync::API.new("token")
11
+ expect(client).to be_kind_of(BookingSync::API::Client)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,57 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://www.bookingsync.com/api/v3/bookings
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.0
12
+ Accept:
13
+ - application/vnd.api+json
14
+ Authorization:
15
+ - Bearer <<ACCESS_TOKEN>>
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ X-Ratelimit-Limit:
24
+ - '1000'
25
+ X-Ratelimit-Reset:
26
+ - '1394193600'
27
+ X-Ratelimit-Remaining:
28
+ - '995'
29
+ Access-Control-Allow-Origin:
30
+ - "*"
31
+ Access-Control-Request-Method:
32
+ - "*"
33
+ Content-Type:
34
+ - application/vnd.api+json; charset=utf-8
35
+ X-Ua-Compatible:
36
+ - IE=Edge
37
+ Etag:
38
+ - "\"435e6e3ac9649b612515cf4bc58d6643\""
39
+ Cache-Control:
40
+ - max-age=0, private, must-revalidate
41
+ P3p:
42
+ - CP="OTI DSP COR CUR ADMo DEVo TAI PSAi PSDi IVAi IVDi CONi HISi TELi OTPi
43
+ OUR SAMi OTRo UNRo PUBi IND UNI STA"
44
+ X-Request-Id:
45
+ - 8ceb28412ce6b54c63adfeb683e05ad3
46
+ X-Runtime:
47
+ - '0.161117'
48
+ Date:
49
+ - Fri, 07 Mar 2014 11:28:17 GMT
50
+ Connection:
51
+ - close
52
+ body:
53
+ encoding: UTF-8
54
+ string: "{\"bookings\":[{\"id\":1,\"account_id\":1,\"rental_id\":2,\"start_at\":\"2014-04-28T10:55:13Z\",\"end_at\":\"2014-12-28T10:55:34Z\"},{\"id\":4,\"account_id\":1,\"rental_id\":2,\"start_at\":\"2014-04-28T10:55:13Z\",\"end_at\":\"2014-12-28T10:55:34Z\"}]}"
55
+ http_version:
56
+ recorded_at: Fri, 07 Mar 2014 11:28:17 GMT
57
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,66 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://www.bookingsync.com/api/v3/rentals
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.9
12
+ Accept:
13
+ - application/vnd.api+json
14
+ Authorization:
15
+ - Bearer <<ACCESS_TOKEN>>
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ X-Ratelimit-Limit:
24
+ - '1000'
25
+ X-Ratelimit-Reset:
26
+ - '1393963200'
27
+ X-Ratelimit-Remaining:
28
+ - '998'
29
+ Access-Control-Allow-Origin:
30
+ - "*"
31
+ Access-Control-Request-Method:
32
+ - "*"
33
+ Content-Type:
34
+ - application/vnd.api+json; charset=utf-8
35
+ X-Ua-Compatible:
36
+ - IE=Edge
37
+ Etag:
38
+ - "\"ddf4735a349a4822af7cc71fa3cf5869\""
39
+ Cache-Control:
40
+ - max-age=0, private, must-revalidate
41
+ P3p:
42
+ - CP="OTI DSP COR CUR ADMo DEVo TAI PSAi PSDi IVAi IVDi CONi HISi TELi OTPi
43
+ OUR SAMi OTRo UNRo PUBi IND UNI STA"
44
+ X-Request-Id:
45
+ - a7d144d12012bb2652e2f421b301ea3a
46
+ X-Runtime:
47
+ - '0.183894'
48
+ Date:
49
+ - Tue, 04 Mar 2014 19:55:10 GMT
50
+ Connection:
51
+ - close
52
+ body:
53
+ encoding: UTF-8
54
+ string: "{\"rentals\":[{\"links\":{\"photos\":[]},\"account_id\":1,\"id\":2,\"name\":\"0
55
+ est\",\"headline\":{\"en\":\"Super Headline\"},\"summary\":{\"en\":\"Super
56
+ summary\"},\"description\":{\"en\":\"Complete description\"},\"rental_type\":\"villa\",\"units\":1,\"bedrooms\":null,\"sleeps\":7,\"sleeps_max\":null,\"bathrooms\":3,\"surface\":120,\"bookable_online\":false,\"min_price\":700,\"max_price\":700,\"price_kind\":\"weekly\",\"currency\":\"EUR\",\"rates_public_notes\":{\"en\":null},\"lat\":45.02,\"lng\":6.6,\"city\":\"Nevache\",\"state\":null,\"country\":\"France\",\"contact_name\":\"Contact
57
+ Fullname\",\"amenities\":[],\"reviews_count\":0,\"reviews_average_rating\":null,\"updated_at\":\"2014-02-11T09:13:20Z\"},{\"links\":{\"photos\":[2]},\"account_id\":1,\"id\":4,\"name\":\"1
58
+ et\",\"headline\":{\"en\":\"Super Headline\"},\"summary\":{\"en\":\"Super
59
+ summary\"},\"description\":{\"en\":\"Complete description\"},\"rental_type\":\"villa\",\"units\":1,\"bedrooms\":null,\"sleeps\":7,\"sleeps_max\":null,\"bathrooms\":3,\"surface\":120,\"bookable_online\":false,\"min_price\":700,\"max_price\":700,\"price_kind\":\"weekly\",\"currency\":\"EUR\",\"rates_public_notes\":{\"en\":null},\"lat\":45.02,\"lng\":6.6,\"city\":\"Nevache\",\"state\":null,\"country\":\"France\",\"contact_name\":\"Contact
60
+ Fullname\",\"amenities\":[],\"reviews_count\":0,\"reviews_average_rating\":null,\"updated_at\":\"2014-02-11T09:13:25Z\"},{\"links\":{\"photos\":[]},\"account_id\":1,\"id\":6,\"name\":\"2
61
+ officiis\",\"headline\":{\"en\":\"Super Headline\"},\"summary\":{\"en\":\"Super
62
+ summary\"},\"description\":{\"en\":\"Complete description\"},\"rental_type\":\"villa\",\"units\":1,\"bedrooms\":null,\"sleeps\":7,\"sleeps_max\":null,\"bathrooms\":3,\"surface\":120,\"bookable_online\":false,\"min_price\":700,\"max_price\":700,\"price_kind\":\"weekly\",\"currency\":\"EUR\",\"rates_public_notes\":{\"en\":null},\"lat\":45.02,\"lng\":6.6,\"city\":\"Nevache\",\"state\":null,\"country\":\"France\",\"contact_name\":\"Contact
63
+ Fullname\",\"amenities\":[],\"reviews_count\":0,\"reviews_average_rating\":null,\"updated_at\":\"2014-02-28T11:00:58Z\"}]}"
64
+ http_version:
65
+ recorded_at: Tue, 04 Mar 2014 19:55:10 GMT
66
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,57 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://www.bookingsync.com/api/v3/rentals?fields=name
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.0
12
+ Accept:
13
+ - application/vnd.api+json
14
+ Authorization:
15
+ - Bearer <<ACCESS_TOKEN>>
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ X-Ratelimit-Limit:
24
+ - '1000'
25
+ X-Ratelimit-Reset:
26
+ - '1394208000'
27
+ X-Ratelimit-Remaining:
28
+ - '991'
29
+ Access-Control-Allow-Origin:
30
+ - "*"
31
+ Access-Control-Request-Method:
32
+ - "*"
33
+ Content-Type:
34
+ - application/vnd.api+json; charset=utf-8
35
+ X-Ua-Compatible:
36
+ - IE=Edge
37
+ Etag:
38
+ - "\"8bd58448e878aa40ad4737a54ea875a1\""
39
+ Cache-Control:
40
+ - max-age=0, private, must-revalidate
41
+ P3p:
42
+ - CP="OTI DSP COR CUR ADMo DEVo TAI PSAi PSDi IVAi IVDi CONi HISi TELi OTPi
43
+ OUR SAMi OTRo UNRo PUBi IND UNI STA"
44
+ X-Request-Id:
45
+ - d307cea3bd765e0d109b268f8fa8fe3c
46
+ X-Runtime:
47
+ - '0.021144'
48
+ Date:
49
+ - Fri, 07 Mar 2014 15:38:45 GMT
50
+ Connection:
51
+ - close
52
+ body:
53
+ encoding: UTF-8
54
+ string: "{\"rentals\":[{\"name\":\"0 est\"},{\"name\":\"1 et\"}]}"
55
+ http_version:
56
+ recorded_at: Fri, 07 Mar 2014 15:38:45 GMT
57
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,40 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'bookingsync/api'
3
+ require 'webmock/rspec'
4
+ require 'vcr'
5
+ require 'json'
6
+
7
+ RSpec.configure do |config|
8
+ config.before do
9
+ ENV["BOOKINGSYNC_VERIFY_SSL"] = "false"
10
+ end
11
+ config.include WebMock::API
12
+ end
13
+
14
+ VCR.configure do |c|
15
+ c.cassette_library_dir = "spec/cassettes"
16
+ c.hook_into :webmock
17
+ c.configure_rspec_metadata!
18
+ c.filter_sensitive_data("<<ACCESS_TOKEN>>") do
19
+ test_access_token
20
+ end
21
+ c.default_cassette_options = {match_requests_on: [:method, :path]}
22
+ end
23
+
24
+ def test_access_token
25
+ ENV.fetch "ACCESS_TOKEN", "fake-access-token"
26
+ end
27
+
28
+ def bs_url(path = "")
29
+ # so that it works when running against local BS API
30
+ url = ENV['BOOKINGSYNC_URL'] || 'https://www.bookingsync.com'
31
+ "#{url}/api/v3/#{path}"
32
+ end
33
+
34
+ def stub_get(path, options = {})
35
+ response = {
36
+ body: {}.to_json,
37
+ headers: {"Content-Type" => "application/vnd.api+json"}
38
+ }.merge(options)
39
+ stub_request(:get, bs_url(path)).to_return(response)
40
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bookingsync-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sébastien Grosjean
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-12 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: '0.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sawyer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: This gem allows to interact with the BookingSync API via Ruby objects
70
+ email:
71
+ - dev@bookingsync.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Guardfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bookingsync-api.gemspec
85
+ - lib/bookingsync/api.rb
86
+ - lib/bookingsync/api/client.rb
87
+ - lib/bookingsync/api/client/bookings.rb
88
+ - lib/bookingsync/api/client/rentals.rb
89
+ - lib/bookingsync/api/error.rb
90
+ - lib/bookingsync/api/middleware/authentication.rb
91
+ - lib/bookingsync/api/version.rb
92
+ - spec/bookingsync/api/client/bookings_spec.rb
93
+ - spec/bookingsync/api/client/rentals_spec.rb
94
+ - spec/bookingsync/api/client_spec.rb
95
+ - spec/bookingsync/api_spec.rb
96
+ - spec/cassettes/BookingSync_API_Client_Bookings/_bookings/returns_bookings.yml
97
+ - spec/cassettes/BookingSync_API_Client_Rentals/_rentals/returns_rentals.yml
98
+ - spec/cassettes/BookingSync_API_Client_Rentals/_rentals/with_specified_fields_in_options/returns_rentals_with_filtered_fields.yml
99
+ - spec/spec_helper.rb
100
+ homepage: https://github.com/BookingSync/bookingsync-api
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.2.0
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Ruby interface for accessing https://www.bookingsync.com
124
+ test_files:
125
+ - spec/bookingsync/api/client/bookings_spec.rb
126
+ - spec/bookingsync/api/client/rentals_spec.rb
127
+ - spec/bookingsync/api/client_spec.rb
128
+ - spec/bookingsync/api_spec.rb
129
+ - spec/cassettes/BookingSync_API_Client_Bookings/_bookings/returns_bookings.yml
130
+ - spec/cassettes/BookingSync_API_Client_Rentals/_rentals/returns_rentals.yml
131
+ - spec/cassettes/BookingSync_API_Client_Rentals/_rentals/with_specified_fields_in_options/returns_rentals_with_filtered_fields.yml
132
+ - spec/spec_helper.rb
133
+ has_rdoc: