nineflats-api 0.0.4 → 0.0.5
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.
- data/README.md +50 -1
- data/lib/nineflats-api.rb +1 -0
- data/lib/nineflats-api/client.rb +52 -0
- data/lib/nineflats-api/query_string_normalizer.rb +48 -0
- data/lib/nineflats-api/requests.rb +19 -0
- data/lib/nineflats-api/user.rb +4 -0
- data/lib/nineflats-api/version.rb +1 -1
- data/nineflats-api.gemspec +2 -1
- metadata +28 -11
data/README.md
CHANGED
@@ -1,4 +1,53 @@
|
|
1
|
-
|
1
|
+
This gem helps you to use the 9flats.com API in your Ruby code. It always uses the latest API version. The current API version is 1.0.
|
2
|
+
|
3
|
+
Find the full API documentation here: http://9flats.github.com/api_docs/
|
4
|
+
|
5
|
+
You can also play around with the API [in your browser](http://nineflats-api-example.heroku.com/).
|
6
|
+
|
7
|
+
### Usage
|
8
|
+
|
9
|
+
Just a few examples:
|
10
|
+
|
11
|
+
#### Get a place with all its attributes:
|
12
|
+
|
13
|
+
place = Place.fetch("schner-wohnen-im-belgischen")
|
14
|
+
place.name
|
15
|
+
place.city
|
16
|
+
|
17
|
+
#### Get more infos about the place:
|
18
|
+
|
19
|
+
place.photos
|
20
|
+
place.reviews
|
21
|
+
place.prices
|
22
|
+
place.calendar(2011, 10)
|
23
|
+
|
24
|
+
Except for the calendar, all data is cached.
|
25
|
+
|
26
|
+
#### Get info about a user:
|
27
|
+
|
28
|
+
user = User.fetch("jana-k-1")
|
29
|
+
user.name
|
30
|
+
user.favorites
|
31
|
+
|
32
|
+
The user's favorites is an array of places, see above.
|
33
|
+
|
34
|
+
#### Search for places:
|
35
|
+
|
36
|
+
The search accepts all search parameters, [see the API documentation](http://9flats.github.com/api_docs/places.html).
|
37
|
+
|
38
|
+
result = Place.search({:query => "Berlin", :number_of_beds => 4})
|
39
|
+
|
40
|
+
The result is a Nineflats::PaginatedArray. It contains the places that match the search queries. The default number of places you get is 9. The result also contains information about the search result, like
|
41
|
+
|
42
|
+
result.total_entries
|
43
|
+
result.total_pages
|
44
|
+
result.current_page
|
45
|
+
result.per_page
|
46
|
+
|
47
|
+
You can also get the next 9 places:
|
48
|
+
|
49
|
+
result.next_page
|
50
|
+
|
2
51
|
|
3
52
|
### How to update this gem
|
4
53
|
|
data/lib/nineflats-api.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'nineflats-api/requests'
|
2
|
+
module Nineflats
|
3
|
+
class Client < Base
|
4
|
+
# API_BASE_URI = "api.9flats.com/api/v1"
|
5
|
+
# API_BASE_URI = "http://localhost.com:3000/api/v1"
|
6
|
+
# WEB_BASE_URI = "http://www.9flats.com"
|
7
|
+
WEB_BASE_URI = "http://localhost.com:3000"
|
8
|
+
|
9
|
+
attr_accessor :request_token
|
10
|
+
attr_accessor :access_token
|
11
|
+
attr_reader :consumer
|
12
|
+
|
13
|
+
include Requests
|
14
|
+
|
15
|
+
def self.connect(api_key, api_secret, options={})
|
16
|
+
@@client = Client.new(api_key, api_secret, options)
|
17
|
+
if block_given?
|
18
|
+
yield @@client
|
19
|
+
end
|
20
|
+
@@client
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.client
|
24
|
+
@@client
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.consumer
|
28
|
+
@@client.consumer
|
29
|
+
end
|
30
|
+
|
31
|
+
def request_token(callback_url)
|
32
|
+
@consumer.get_request_token({:oauth_callback => callback_url})
|
33
|
+
end
|
34
|
+
|
35
|
+
def exchange_access_token(request_token, verifier)
|
36
|
+
request_token.get_access_token(:oauth_verifier => verifier)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def initialize(api_key, api_secret, options={})
|
42
|
+
@consumer = ::OAuth::Consumer.new(api_key, api_secret, {
|
43
|
+
:site => WEB_BASE_URI,
|
44
|
+
:scheme => :header,
|
45
|
+
:http_method => :post
|
46
|
+
})
|
47
|
+
@access_token = options[:access_token]
|
48
|
+
# Client.default_options[:simple_oauth] = { :consumer => @consumer, :method => 'HMAC-SHA1' }.merge(options)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Nineflats
|
2
|
+
module QueryStringNormalizer
|
3
|
+
def self.normalize(query)
|
4
|
+
Array(query).map do |key, value|
|
5
|
+
if value.nil?
|
6
|
+
key.to_s
|
7
|
+
elsif value.is_a?(Array)
|
8
|
+
value.map {|v| "#{key}=#{URI.encode(v.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}"}
|
9
|
+
else
|
10
|
+
HashConversions.to_params(key => value)
|
11
|
+
end
|
12
|
+
end.flatten.sort.join('&')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module HashConversions
|
17
|
+
def self.to_params(hash)
|
18
|
+
params = hash.map { |k,v| normalize_param(k,v) }.join
|
19
|
+
params.chop! # trailing &
|
20
|
+
params
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.normalize_param(key, value)
|
24
|
+
param = ''
|
25
|
+
stack = []
|
26
|
+
|
27
|
+
if value.is_a?(Array)
|
28
|
+
param << value.map { |element| normalize_param("#{key}[]", element) }.join
|
29
|
+
elsif value.is_a?(Hash)
|
30
|
+
stack << [key,value]
|
31
|
+
else
|
32
|
+
param << "#{key}=#{URI.encode(value.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}&"
|
33
|
+
end
|
34
|
+
|
35
|
+
stack.each do |parent, hash|
|
36
|
+
hash.each do |key, value|
|
37
|
+
if value.is_a?(Hash)
|
38
|
+
stack << ["#{parent}[#{key}]", value]
|
39
|
+
else
|
40
|
+
param << normalize_param("#{parent}[#{key}]", value)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
param
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Nineflats
|
2
|
+
module Requests
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def bookings(user_id)
|
9
|
+
params = {:client_id => consumer.key}
|
10
|
+
if client.access_token
|
11
|
+
response = client.access_token.request(:get, "/api/v1/users/#{user_id}/bookings?#{Nineflats::QueryStringNormalizer.normalize(params)}")
|
12
|
+
JSON.parse(response.body)
|
13
|
+
else
|
14
|
+
raise "So what?"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/nineflats-api/user.rb
CHANGED
data/nineflats-api.gemspec
CHANGED
@@ -5,7 +5,7 @@ require "nineflats-api/version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "nineflats-api"
|
7
7
|
s.version = Nineflats::Api::VERSION
|
8
|
-
s.authors = ["Lena Herrmann"]
|
8
|
+
s.authors = ["Lena Herrmann", "Thorsten Böttger"]
|
9
9
|
s.email = ["lena@zeromail.org"]
|
10
10
|
s.homepage = "http://9flats.github.com/api_docs/index.html"
|
11
11
|
s.summary = %q{9flats API}
|
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
|
20
|
+
s.add_runtime_dependency('oauth')
|
20
21
|
s.add_development_dependency('rake', '~> 0.9.0')
|
21
22
|
s.add_development_dependency('rspec')
|
22
23
|
s.add_development_dependency('fakeweb')
|
metadata
CHANGED
@@ -1,19 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nineflats-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Lena Herrmann
|
9
|
+
- Thorsten Böttger
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2011-
|
13
|
+
date: 2011-11-02 00:00:00.000000000 +01:00
|
14
|
+
default_executable:
|
13
15
|
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: oauth
|
18
|
+
requirement: &2152240100 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *2152240100
|
14
27
|
- !ruby/object:Gem::Dependency
|
15
28
|
name: rake
|
16
|
-
requirement: &
|
29
|
+
requirement: &2152239300 !ruby/object:Gem::Requirement
|
17
30
|
none: false
|
18
31
|
requirements:
|
19
32
|
- - ~>
|
@@ -21,10 +34,10 @@ dependencies:
|
|
21
34
|
version: 0.9.0
|
22
35
|
type: :development
|
23
36
|
prerelease: false
|
24
|
-
version_requirements: *
|
37
|
+
version_requirements: *2152239300
|
25
38
|
- !ruby/object:Gem::Dependency
|
26
39
|
name: rspec
|
27
|
-
requirement: &
|
40
|
+
requirement: &2152238760 !ruby/object:Gem::Requirement
|
28
41
|
none: false
|
29
42
|
requirements:
|
30
43
|
- - ! '>='
|
@@ -32,10 +45,10 @@ dependencies:
|
|
32
45
|
version: '0'
|
33
46
|
type: :development
|
34
47
|
prerelease: false
|
35
|
-
version_requirements: *
|
48
|
+
version_requirements: *2152238760
|
36
49
|
- !ruby/object:Gem::Dependency
|
37
50
|
name: fakeweb
|
38
|
-
requirement: &
|
51
|
+
requirement: &2152238080 !ruby/object:Gem::Requirement
|
39
52
|
none: false
|
40
53
|
requirements:
|
41
54
|
- - ! '>='
|
@@ -43,7 +56,7 @@ dependencies:
|
|
43
56
|
version: '0'
|
44
57
|
type: :development
|
45
58
|
prerelease: false
|
46
|
-
version_requirements: *
|
59
|
+
version_requirements: *2152238080
|
47
60
|
description: Let's you use the 9flats API'
|
48
61
|
email:
|
49
62
|
- lena@zeromail.org
|
@@ -59,11 +72,14 @@ files:
|
|
59
72
|
- lib/nineflats-api.rb
|
60
73
|
- lib/nineflats-api/base.rb
|
61
74
|
- lib/nineflats-api/calendar.rb
|
75
|
+
- lib/nineflats-api/client.rb
|
62
76
|
- lib/nineflats-api/helpers.rb
|
63
77
|
- lib/nineflats-api/paginated_array.rb
|
64
78
|
- lib/nineflats-api/photo.rb
|
65
79
|
- lib/nineflats-api/place.rb
|
66
80
|
- lib/nineflats-api/prices.rb
|
81
|
+
- lib/nineflats-api/query_string_normalizer.rb
|
82
|
+
- lib/nineflats-api/requests.rb
|
67
83
|
- lib/nineflats-api/review.rb
|
68
84
|
- lib/nineflats-api/season.rb
|
69
85
|
- lib/nineflats-api/user.rb
|
@@ -86,6 +102,7 @@ files:
|
|
86
102
|
- spec/search_spec.rb
|
87
103
|
- spec/spec_helper.rb
|
88
104
|
- spec/user_spec.rb
|
105
|
+
has_rdoc: true
|
89
106
|
homepage: http://9flats.github.com/api_docs/index.html
|
90
107
|
licenses: []
|
91
108
|
post_install_message:
|
@@ -100,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
117
|
version: '0'
|
101
118
|
segments:
|
102
119
|
- 0
|
103
|
-
hash: -
|
120
|
+
hash: -3354025967072406112
|
104
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
122
|
none: false
|
106
123
|
requirements:
|
@@ -109,10 +126,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
126
|
version: '0'
|
110
127
|
segments:
|
111
128
|
- 0
|
112
|
-
hash: -
|
129
|
+
hash: -3354025967072406112
|
113
130
|
requirements: []
|
114
131
|
rubyforge_project:
|
115
|
-
rubygems_version: 1.
|
132
|
+
rubygems_version: 1.6.2
|
116
133
|
signing_key:
|
117
134
|
specification_version: 3
|
118
135
|
summary: 9flats API
|