is24 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/is24.rb +130 -30
- data/lib/is24/version.rb +1 -1
- metadata +18 -37
- data/lib/bnerd-video.rb~ +0 -70
- data/lib/bnerd.rb~ +0 -71
- data/lib/bnerd_video.rb~ +0 -92
- data/lib/is24.rb~ +0 -122
- data/lib/is24/client.rb~ +0 -10
- data/lib/is24/logger.rb~ +0 -10
- data/lib/is24/version.rb~ +0 -3
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 796f124dc5b42c1ee9f57e39c53fadddc1d58114
|
4
|
+
data.tar.gz: 793b91c0edc90b4d7bfedbd687a018853fb9019c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c6cb236fbc76269422ac79adcb30f32618dd464292cc6caf5ad99e4e5d60d1b1d908fccbcf62dc13fc68e790ae46caed76d9f37a4dfba5fec18e0c97b0d708e
|
7
|
+
data.tar.gz: 9e8318bc6f05d68200d337b68d47f64d1ea36edfd772f7b791dfcaee361b51cd1716afff5af21fa65c838506f0ba1b22f136629772c358cc81622f7f1d611204
|
data/lib/is24.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'is24/logger'
|
2
4
|
require 'faraday'
|
3
5
|
require 'faraday_middleware'
|
@@ -9,23 +11,90 @@ module Is24
|
|
9
11
|
include Is24::Logger
|
10
12
|
|
11
13
|
API_ENDPOINT = "http://rest.immobilienscout24.de/restapi/api/search/v1.0/"
|
14
|
+
API_OFFER_ENDPOINT = "http://rest.immobilienscout24.de/restapi/api/offer/v1.0/"
|
12
15
|
API_AUTHORIZATION_ENDPOINT = "http://rest.immobilienscout24.de/restapi/security/"
|
13
16
|
|
17
|
+
# TODO move in separate module
|
18
|
+
MARKETING_TYPES = {
|
19
|
+
"PURCHASE" => "Kauf",
|
20
|
+
"PURCHASE_PER_SQM" => "Kaufpreis/ Quadratmeter",
|
21
|
+
"RENT" => "Miete",
|
22
|
+
"RENT_PER_SQM" => "Mietpreis/ Quadratmeter",
|
23
|
+
"LEASE" => "Leasing",
|
24
|
+
"LEASEHOLD" => "",
|
25
|
+
"BUDGET_RENT" => "",
|
26
|
+
"RENT_AND_BUY" => ""
|
27
|
+
}
|
28
|
+
|
29
|
+
PRICE_INTERVAL_TYPES = {
|
30
|
+
"DAY" => "Tag",
|
31
|
+
"WEEK" => "Woche",
|
32
|
+
"MONTH" => "Monat",
|
33
|
+
"YEAR" => "Jahr",
|
34
|
+
"ONE_TIME_CHARGE" => "einmalig"
|
35
|
+
}
|
36
|
+
|
37
|
+
REAL_ESTATE_TYPES = {
|
38
|
+
"APARTMENT_RENT" => "Wohnung Miete",
|
39
|
+
"APARTMENT_BUY" => "Wohnung Kauf",
|
40
|
+
"HOUSE_RENT" => "Haus Miete",
|
41
|
+
"HOUSE_BUY" => "Haus Kauf",
|
42
|
+
"GARAGE_RENT" => "Garage / Stellplatz Miete",
|
43
|
+
"GARAGE_BUY" => "Garage / Stellplatz Kauf",
|
44
|
+
"LIVING_RENT_SITE" => "Grundstück Wohnen Miete",
|
45
|
+
"LIVING_BUY_SITE" => "Grundstück Wohnen Kauf",
|
46
|
+
"TRADE_SITE" => "Grundstück Gewerbe",
|
47
|
+
"HOUSE_TYPE" => "Typenhäuser",
|
48
|
+
"FLAT_SHARE_ROOM" => "WG-Zimmer",
|
49
|
+
"SENIOR_CARE" => "Altenpflege",
|
50
|
+
"ASSISTED_LIVING" => "Betreutes Wohnen",
|
51
|
+
"OFFICE" => "Büro / Praxis",
|
52
|
+
"INDUSTRY" => "Hallen / Produktion",
|
53
|
+
"STORE" => "Einzelhandel",
|
54
|
+
"GASTRONOMY" => "Gastronomie / Hotel",
|
55
|
+
"SPECIAL_PURPOSE" => "",
|
56
|
+
"INVESTMENT" => "Gewerbeprojekte",
|
57
|
+
"COMPULSORY_AUCTION" => "",
|
58
|
+
"SHORT_TERM_ACCOMMODATION" => ""
|
59
|
+
}
|
60
|
+
|
61
|
+
# transforms, eg.
|
62
|
+
# "SPECIAL_PURPOSE" => ""
|
63
|
+
# to
|
64
|
+
# "search:SpecialPurpose" => ""
|
65
|
+
XSI_SEARCH_TYPES = lambda {
|
66
|
+
return Hash[*REAL_ESTATE_TYPES.map{ |v|
|
67
|
+
[
|
68
|
+
"search:"+v.first.downcase.split("_").map!(&:capitalize).join,
|
69
|
+
v[1]
|
70
|
+
]
|
71
|
+
}.flatten
|
72
|
+
]
|
73
|
+
}.()
|
74
|
+
|
75
|
+
def self.format_marketing_type(marketing_type)
|
76
|
+
MARKETING_TYPES[marketing_type] || ""
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.format_price_interval_type(price_interval_type)
|
80
|
+
PRICE_INTERVAL_TYPES[price_interval_type] || ""
|
81
|
+
end
|
82
|
+
|
14
83
|
def initialize( options = {} )
|
15
84
|
logger "Initialized b'nerd IS24 with options #{options}"
|
16
|
-
|
85
|
+
|
17
86
|
@token = options[:token] || nil
|
18
87
|
@secret = options[:secret] || nil
|
19
88
|
@consumer_secret = options[:consumer_secret] || nil
|
20
89
|
@consumer_key = options[:consumer_key] || nil
|
21
|
-
|
90
|
+
|
22
91
|
raise "Missing Credentials!" if @consumer_secret.nil? || @consumer_key.nil?
|
23
92
|
end
|
24
|
-
|
93
|
+
|
25
94
|
def request_token( callback_uri )
|
26
95
|
# TODO error handling
|
27
96
|
response = connection(:authorization, callback_uri).get("oauth/request_token")
|
28
|
-
|
97
|
+
|
29
98
|
body = response.body.split('&')
|
30
99
|
response = {
|
31
100
|
:oauth_token => CGI::unescape(body[0].split("=")[1]),
|
@@ -41,75 +110,106 @@ module Is24
|
|
41
110
|
@secret = params[:oauth_token_secret]
|
42
111
|
|
43
112
|
response = connection(:authorization).get("oauth/access_token")
|
44
|
-
puts response.inspect
|
45
113
|
body = response.body.split('&')
|
46
|
-
|
114
|
+
|
47
115
|
response = {
|
48
116
|
:oauth_token => body[0].split('=')[1],
|
49
117
|
:oauth_token_secret => CGI::unescape(body[1].split('=')[1]),
|
50
118
|
}
|
51
|
-
|
119
|
+
|
52
120
|
# set credentials in client
|
53
121
|
@token = response[:oauth_token]
|
54
122
|
@token_secret = response[:oauth_token_secret]
|
55
|
-
|
123
|
+
|
56
124
|
# return access token and secret
|
57
125
|
response
|
58
126
|
end
|
59
|
-
|
127
|
+
|
60
128
|
def search(options)
|
61
129
|
defaults = {
|
62
130
|
:channel => "hp",
|
63
|
-
:realestatetype => "housebuy",
|
131
|
+
:realestatetype => ["housebuy"],
|
64
132
|
:geocodes => 1276,
|
65
|
-
:username => "me"
|
133
|
+
:username => "me"
|
66
134
|
}
|
67
135
|
options = defaults.merge(options)
|
68
|
-
|
69
|
-
|
70
|
-
|
136
|
+
types = options[:realestatetype]
|
137
|
+
|
138
|
+
case types
|
139
|
+
when String
|
140
|
+
types = [types]
|
141
|
+
end
|
142
|
+
|
143
|
+
objects = []
|
144
|
+
|
145
|
+
types.each do |type|
|
146
|
+
options[:realestatetype] = type
|
147
|
+
response = connection.get("search/region", options )
|
148
|
+
if response.status == 200
|
149
|
+
if response.body["resultlist.resultlist"].resultlistEntries[0]['@numberOfHits'] == "0"
|
150
|
+
response.body["resultlist.resultlist"].resultlistEntries[0].resultlistEntries = []
|
151
|
+
end
|
152
|
+
objects.push response.body["resultlist.resultlist"].resultlistEntries[0]
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
objects
|
71
157
|
end
|
72
|
-
|
158
|
+
|
73
159
|
def expose(id)
|
74
160
|
response = connection.get("expose/#{id}")
|
75
161
|
response.body["expose.expose"]
|
76
162
|
end
|
77
|
-
|
163
|
+
|
164
|
+
def list_exposes
|
165
|
+
response = connection(:offer).get("user/me/realestate?publishchannel=IS24")
|
166
|
+
response.body
|
167
|
+
end
|
168
|
+
|
169
|
+
def short_list
|
170
|
+
response = connection.get("searcher/me/shortlist/0/entry")
|
171
|
+
response.body["shortlist.shortlistEntries"].first["shortlistEntry"]
|
172
|
+
end
|
173
|
+
|
78
174
|
protected
|
79
|
-
|
175
|
+
|
80
176
|
def connection(connection_type = :default, callback_uri = nil)
|
81
|
-
|
177
|
+
|
82
178
|
# set request defaults
|
83
179
|
defaults = {
|
84
180
|
:url => API_ENDPOINT,
|
85
|
-
:accept => 'application/json',
|
86
181
|
:headers => {
|
87
182
|
:accept => 'application/json',
|
88
|
-
:user_agent => 'b\'nerd .media IS24 Ruby Client'}
|
183
|
+
:user_agent => 'b\'nerd .media IS24 Ruby Client'}
|
89
184
|
}
|
90
|
-
|
185
|
+
|
91
186
|
defaults.merge!( {
|
92
187
|
:url => API_AUTHORIZATION_ENDPOINT
|
93
188
|
} ) if connection_type =~ /authorization/i
|
94
|
-
|
189
|
+
|
190
|
+
defaults.merge!( {
|
191
|
+
:url => API_OFFER_ENDPOINT
|
192
|
+
} ) if connection_type =~ /offer/i
|
193
|
+
|
194
|
+
|
95
195
|
# define oauth credentials
|
96
196
|
oauth = {
|
97
|
-
:consumer_key => @consumer_key,
|
98
|
-
:consumer_secret => @consumer_secret,
|
99
|
-
:token => @token,
|
197
|
+
:consumer_key => @consumer_key,
|
198
|
+
:consumer_secret => @consumer_secret,
|
199
|
+
:token => @token,
|
100
200
|
:token_secret => @secret
|
101
201
|
}
|
102
|
-
|
202
|
+
|
103
203
|
# merge callback_uri if present
|
104
204
|
oauth.merge!( {
|
105
205
|
:callback => callback_uri
|
106
206
|
} ) if connection_type =~ /authorization/i && callback_uri
|
107
|
-
|
207
|
+
|
108
208
|
# merge verifier if present
|
109
209
|
oauth.merge!( {
|
110
210
|
:verifier => @oauth_verifier
|
111
211
|
} ) if connection_type =~ /authorization/i && @oauth_verifier
|
112
|
-
|
212
|
+
|
113
213
|
Faraday::Connection.new( defaults ) do |builder|
|
114
214
|
builder.request :oauth, oauth
|
115
215
|
builder.response :mashify
|
@@ -117,6 +217,6 @@ module Is24
|
|
117
217
|
builder.adapter Faraday.default_adapter
|
118
218
|
end
|
119
219
|
end
|
120
|
-
|
220
|
+
|
121
221
|
end
|
122
|
-
end
|
222
|
+
end
|
data/lib/is24/version.rb
CHANGED
metadata
CHANGED
@@ -1,94 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: is24
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Bernd Suenkel
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-04-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: multi_json
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: hashie
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: faraday
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: faraday_middleware
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: simple_oauth
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :runtime
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
description: Simple Ruby API Client for Immobilienscout24.
|
@@ -98,41 +87,33 @@ executables: []
|
|
98
87
|
extensions: []
|
99
88
|
extra_rdoc_files: []
|
100
89
|
files:
|
101
|
-
- lib/is24.rb
|
90
|
+
- lib/is24.rb
|
102
91
|
- lib/is24/version.rb
|
103
92
|
- lib/is24/logger.rb
|
104
|
-
- lib/is24/logger.rb~
|
105
|
-
- lib/is24/client.rb~
|
106
|
-
- lib/is24/version.rb~
|
107
|
-
- lib/bnerd-video.rb~
|
108
|
-
- lib/bnerd_video.rb~
|
109
|
-
- lib/bnerd.rb~
|
110
|
-
- lib/is24.rb
|
111
93
|
- LICENSE.txt
|
112
94
|
- Rakefile
|
113
95
|
- README.md
|
114
96
|
homepage: http://github.com/bnerd/is24
|
115
97
|
licenses: []
|
98
|
+
metadata: {}
|
116
99
|
post_install_message:
|
117
100
|
rdoc_options: []
|
118
101
|
require_paths:
|
119
102
|
- lib
|
120
103
|
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
104
|
requirements:
|
123
|
-
- -
|
105
|
+
- - '>='
|
124
106
|
- !ruby/object:Gem::Version
|
125
107
|
version: '0'
|
126
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
-
none: false
|
128
109
|
requirements:
|
129
|
-
- -
|
110
|
+
- - '>='
|
130
111
|
- !ruby/object:Gem::Version
|
131
112
|
version: '0'
|
132
113
|
requirements: []
|
133
114
|
rubyforge_project:
|
134
|
-
rubygems_version:
|
115
|
+
rubygems_version: 2.0.3
|
135
116
|
signing_key:
|
136
|
-
specification_version:
|
117
|
+
specification_version: 4
|
137
118
|
summary: Ruby API Client for Immobilienscout24.
|
138
119
|
test_files: []
|
data/lib/bnerd-video.rb~
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'faraday_middleware'
|
3
|
-
require 'faraday_middleware/response/mashify'
|
4
|
-
|
5
|
-
module Bnerd
|
6
|
-
class Api
|
7
|
-
|
8
|
-
def initialize( options = {} )
|
9
|
-
@secret = options[:secret] || nil
|
10
|
-
@api_key = options[:api_key] || nil
|
11
|
-
@public_key = options[:public_key] || nil
|
12
|
-
raise "Invalid Credentials" if @secret.nil? || @api_key.nil?
|
13
|
-
end
|
14
|
-
|
15
|
-
def videos
|
16
|
-
connection.get('videos').body
|
17
|
-
end
|
18
|
-
|
19
|
-
def video(id)
|
20
|
-
connection.get("videos/#{id}").body.video
|
21
|
-
end
|
22
|
-
|
23
|
-
def ingest
|
24
|
-
params = {
|
25
|
-
api_key: @api_key,
|
26
|
-
public_key: "f3bbb86e4d9b9a7a60e0b10ba0312535",
|
27
|
-
timestamp: 1360459978,
|
28
|
-
signature: '1325ea0ed234cbfceafcff19cc3732731da0d26af3a99f61f57195b271f190cc',
|
29
|
-
video: {
|
30
|
-
name: "foo",
|
31
|
-
description: "bar",
|
32
|
-
data: Faraday::UploadIO.new('/home/besu/Videos/second/178969.flv', 'video/mp4')
|
33
|
-
}
|
34
|
-
}
|
35
|
-
ingest_connection.post("/", params)
|
36
|
-
end
|
37
|
-
|
38
|
-
protected
|
39
|
-
|
40
|
-
def ingest_connection
|
41
|
-
Faraday::Connection.new(
|
42
|
-
:url => "https://ingest.bnerd.net:8043",
|
43
|
-
:ssl => { verify: false },
|
44
|
-
:headers => {
|
45
|
-
:user_agent => 'b\'nerd .video Ruby Client'}
|
46
|
-
) do |builder|
|
47
|
-
builder.request :multipart
|
48
|
-
builder.request :url_encoded
|
49
|
-
builder.adapter Faraday.default_adapter
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def connection
|
54
|
-
Faraday::Connection.new(
|
55
|
-
:url => "http://video.bnerd.net/api/v1",
|
56
|
-
:accept => 'application/json',
|
57
|
-
:params => {
|
58
|
-
auth_token: @secret,
|
59
|
-
api_key: @api_key
|
60
|
-
},
|
61
|
-
:headers => {
|
62
|
-
:accept => 'application/json',
|
63
|
-
:user_agent => 'b\'nerd .video Ruby Client'} ) do |builder|
|
64
|
-
builder.response :mashify
|
65
|
-
builder.response :json
|
66
|
-
builder.adapter Faraday.default_adapter
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
data/lib/bnerd.rb~
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'faraday_middleware'
|
3
|
-
require 'faraday_middleware/response/mashify'
|
4
|
-
require './bnerd/api/logger'
|
5
|
-
|
6
|
-
module Bnerd
|
7
|
-
class Api
|
8
|
-
|
9
|
-
def initialize( options = {} )
|
10
|
-
@secret = options[:secret] || nil
|
11
|
-
@api_key = options[:api_key] || nil
|
12
|
-
@public_key = options[:public_key] || nil
|
13
|
-
raise "Invalid Credentials" if @secret.nil? || @api_key.nil?
|
14
|
-
end
|
15
|
-
|
16
|
-
def videos
|
17
|
-
connection.get('videos').body
|
18
|
-
end
|
19
|
-
|
20
|
-
def video(id)
|
21
|
-
connection.get("videos/#{id}").body.video
|
22
|
-
end
|
23
|
-
|
24
|
-
def ingest
|
25
|
-
params = {
|
26
|
-
api_key: @api_key,
|
27
|
-
public_key: "f3bbb86e4d9b9a7a60e0b10ba0312535",
|
28
|
-
timestamp: 1360459978,
|
29
|
-
signature: '1325ea0ed234cbfceafcff19cc3732731da0d26af3a99f61f57195b271f190cc',
|
30
|
-
video: {
|
31
|
-
name: "foo",
|
32
|
-
description: "bar",
|
33
|
-
data: Faraday::UploadIO.new('/home/besu/Videos/second/178969.flv', 'video/mp4')
|
34
|
-
}
|
35
|
-
}
|
36
|
-
ingest_connection.post("/", params)
|
37
|
-
end
|
38
|
-
|
39
|
-
protected
|
40
|
-
|
41
|
-
def ingest_connection
|
42
|
-
Faraday::Connection.new(
|
43
|
-
:url => "https://ingest.bnerd.net:8043",
|
44
|
-
:ssl => { verify: false },
|
45
|
-
:headers => {
|
46
|
-
:user_agent => 'b\'nerd .video Ruby Client'}
|
47
|
-
) do |builder|
|
48
|
-
builder.request :multipart
|
49
|
-
builder.request :url_encoded
|
50
|
-
builder.adapter Faraday.default_adapter
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def connection
|
55
|
-
Faraday::Connection.new(
|
56
|
-
:url => "http://video.bnerd.net/api/v1",
|
57
|
-
:accept => 'application/json',
|
58
|
-
:params => {
|
59
|
-
auth_token: @secret,
|
60
|
-
api_key: @api_key
|
61
|
-
},
|
62
|
-
:headers => {
|
63
|
-
:accept => 'application/json',
|
64
|
-
:user_agent => 'b\'nerd .video Ruby Client'} ) do |builder|
|
65
|
-
builder.response :mashify
|
66
|
-
builder.response :json
|
67
|
-
builder.adapter Faraday.default_adapter
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
data/lib/bnerd_video.rb~
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'faraday_middleware'
|
3
|
-
require 'faraday_middleware/response/mashify'
|
4
|
-
require 'bnerd_video/logger'
|
5
|
-
require 'bnerd_video/model/video'
|
6
|
-
|
7
|
-
module BnerdVideo
|
8
|
-
class Api
|
9
|
-
include BnerdVideo::Logger
|
10
|
-
|
11
|
-
# PRODUCTION
|
12
|
-
API_ENDPOINT = "http://video.bnerd.net/api/v1"
|
13
|
-
INGEST_ENDPOINT = "https://ingest.bnerd.net:8043"
|
14
|
-
|
15
|
-
# DEVELOPMENT
|
16
|
-
API_ENDPOINT = "http://video.lvh.me:3000/api/v1"
|
17
|
-
INGEST_ENDPOINT = "https://ingest.bnerd.net:8043"
|
18
|
-
|
19
|
-
def initialize( options = {} )
|
20
|
-
logger "Initialized BnerdVideo with options #{options}"
|
21
|
-
|
22
|
-
@secret = options[:secret] || nil
|
23
|
-
@api_key = options[:api_key] || nil
|
24
|
-
@public_key = options[:public_key] || nil
|
25
|
-
raise "Invalid Credentials" if @secret.nil? || @api_key.nil?
|
26
|
-
end
|
27
|
-
|
28
|
-
def videos
|
29
|
-
response = connection.get('videos')
|
30
|
-
response.body.videos.map do |video|
|
31
|
-
BnerdVideo::Model::Video.new(video, self)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def video(id)
|
36
|
-
response = connection.get("videos/#{id}")
|
37
|
-
BnerdVideo::Model::Video.new(response.body, self)
|
38
|
-
end
|
39
|
-
|
40
|
-
def ingest(media, params)
|
41
|
-
ingest_connection.post("/", params)
|
42
|
-
end
|
43
|
-
|
44
|
-
def update(model)
|
45
|
-
response = connection.put("videos/#{model.id}") do |req|
|
46
|
-
req.headers['Content-Type'] = 'application/json'
|
47
|
-
req.body = model.to_json
|
48
|
-
end
|
49
|
-
BnerdVideo::Model::Video.new(response.body, self)
|
50
|
-
end
|
51
|
-
|
52
|
-
def destroy(model)
|
53
|
-
response = connection.delete("videos/#{model.id}") do |req|
|
54
|
-
req.headers['Content-Type'] = 'application/json'
|
55
|
-
req.body = model.to_json
|
56
|
-
end
|
57
|
-
BnerdVideo::Model::Video.new(response.body, self)
|
58
|
-
end
|
59
|
-
|
60
|
-
protected
|
61
|
-
|
62
|
-
def ingest_connection
|
63
|
-
Faraday::Connection.new(
|
64
|
-
:url => INGEST_ENDPOINT,
|
65
|
-
:ssl => { verify: false },
|
66
|
-
:headers => {
|
67
|
-
:user_agent => 'b\'nerd .video Ruby Client'}
|
68
|
-
) do |builder|
|
69
|
-
builder.request :multipart
|
70
|
-
builder.request :url_encoded
|
71
|
-
builder.adapter Faraday.default_adapter
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def connection
|
76
|
-
Faraday::Connection.new(
|
77
|
-
:url => API_ENDPOINT,
|
78
|
-
:accept => 'application/json',
|
79
|
-
:params => {
|
80
|
-
auth_token: @secret,
|
81
|
-
api_key: @api_key
|
82
|
-
},
|
83
|
-
:headers => {
|
84
|
-
:accept => 'application/json',
|
85
|
-
:user_agent => 'b\'nerd .video Ruby Client'} ) do |builder|
|
86
|
-
builder.response :mashify
|
87
|
-
builder.response :json
|
88
|
-
builder.adapter Faraday.default_adapter
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
data/lib/is24.rb~
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'is24/logger'
|
2
|
-
require 'faraday'
|
3
|
-
require 'faraday_middleware'
|
4
|
-
require 'faraday_middleware/response/mashify'
|
5
|
-
require 'cgi'
|
6
|
-
|
7
|
-
module Is24
|
8
|
-
class Api
|
9
|
-
include Is24::Logger
|
10
|
-
|
11
|
-
API_ENDPOINT = "http://rest.immobilienscout24.de/restapi/api/search/v1.0/"
|
12
|
-
API_AUTHORIZATION_ENDPOINT = "http://rest.immobilienscout24.de/restapi/security/"
|
13
|
-
|
14
|
-
def initialize( options = {} )
|
15
|
-
logger "Initialized b'nerd IS24 with options #{options}"
|
16
|
-
|
17
|
-
@token = options[:token] || nil
|
18
|
-
@secret = options[:secret] || nil
|
19
|
-
@consumer_secret = options[:consumer_secret] || nil
|
20
|
-
@consumer_key = options[:consumer_key] || nil
|
21
|
-
|
22
|
-
raise "Missing Credentials!" if @consumer_secret.nil? || @consumer_key.nil?
|
23
|
-
end
|
24
|
-
|
25
|
-
def request_token( callback_uri )
|
26
|
-
# TODO error handling
|
27
|
-
response = connection(:authorization, callback_uri).get("oauth/request_token")
|
28
|
-
|
29
|
-
body = response.body.split('&')
|
30
|
-
response = {
|
31
|
-
:oauth_token => CGI::unescape(body[0].split("=")[1]),
|
32
|
-
:oauth_token_secret => CGI::unescape(body[1].split("=")[1]),
|
33
|
-
:redirect_uri => "http://rest.immobilienscout24.de/restapi/security/oauth/confirm_access?#{body[0]}"
|
34
|
-
}
|
35
|
-
end
|
36
|
-
|
37
|
-
def request_access_token( params = {} )
|
38
|
-
# TODO error handling
|
39
|
-
@oauth_verifier = params[:oauth_verifier]
|
40
|
-
@token = params[:oauth_token]
|
41
|
-
@secret = params[:oauth_token_secret]
|
42
|
-
|
43
|
-
response = connection(:authorization).get("oauth/access_token")
|
44
|
-
puts response.inspect
|
45
|
-
body = response.body.split('&')
|
46
|
-
|
47
|
-
response = {
|
48
|
-
:oauth_token => body[0].split('=')[1],
|
49
|
-
:oauth_token_secret => CGI::unescape(body[1].split('=')[1]),
|
50
|
-
}
|
51
|
-
|
52
|
-
# set credentials in client
|
53
|
-
@token = response[:oauth_token]
|
54
|
-
@token_secret = response[:oauth_token_secret]
|
55
|
-
|
56
|
-
# return access token and secret
|
57
|
-
response
|
58
|
-
end
|
59
|
-
|
60
|
-
def search(options)
|
61
|
-
defaults = {
|
62
|
-
:channel => "hp",
|
63
|
-
:realestatetype => "housebuy",
|
64
|
-
:geocodes => 1276,
|
65
|
-
:username => "me"
|
66
|
-
}
|
67
|
-
options = defaults.merge(options)
|
68
|
-
|
69
|
-
response = connection.get("search/region", options )
|
70
|
-
response.body["resultlist.resultlist"]
|
71
|
-
end
|
72
|
-
|
73
|
-
def expose(id)
|
74
|
-
response = connection.get("expose/#{id}")
|
75
|
-
response.body["expose.expose"]
|
76
|
-
end
|
77
|
-
|
78
|
-
protected
|
79
|
-
|
80
|
-
def connection(connection_type = :default, callback_uri = nil)
|
81
|
-
|
82
|
-
# set request defaults
|
83
|
-
defaults = {
|
84
|
-
:url => API_ENDPOINT,
|
85
|
-
:accept => 'application/json',
|
86
|
-
:headers => {
|
87
|
-
:accept => 'application/json',
|
88
|
-
:user_agent => 'b\'nerd .media IS24 Ruby Client'}
|
89
|
-
}
|
90
|
-
|
91
|
-
defaults.merge!( {
|
92
|
-
:url => API_AUTHORIZATION_ENDPOINT
|
93
|
-
} ) if connection_type =~ /authorization/i
|
94
|
-
|
95
|
-
# define oauth credentials
|
96
|
-
oauth = {
|
97
|
-
:consumer_key => @consumer_key,
|
98
|
-
:consumer_secret => @consumer_secret,
|
99
|
-
:token => @token,
|
100
|
-
:token_secret => @secret
|
101
|
-
}
|
102
|
-
|
103
|
-
# merge callback_uri if present
|
104
|
-
oauth.merge!( {
|
105
|
-
:callback => callback_uri
|
106
|
-
} ) if connection_type =~ /authorization/i && callback_uri
|
107
|
-
|
108
|
-
# merge verifier if present
|
109
|
-
oauth.merge!( {
|
110
|
-
:verifier => @oauth_verifier
|
111
|
-
} ) if connection_type =~ /authorization/i && @oauth_verifier
|
112
|
-
|
113
|
-
Faraday::Connection.new( defaults ) do |builder|
|
114
|
-
builder.request :oauth, oauth
|
115
|
-
builder.response :mashify
|
116
|
-
builder.response :json unless connection_type =~ /authorization/i
|
117
|
-
builder.adapter Faraday.default_adapter
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|
122
|
-
end
|
data/lib/is24/client.rb~
DELETED
data/lib/is24/logger.rb~
DELETED
data/lib/is24/version.rb~
DELETED