flexmls_api 0.6.5 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +12 -1
- data/VERSION +1 -1
- data/lib/flexmls_api.rb +13 -11
- data/lib/flexmls_api/authentication/api_auth.rb +5 -3
- data/lib/flexmls_api/authentication/oauth2.rb +23 -17
- data/lib/flexmls_api/authentication/oauth2_impl/password_provider.rb +25 -0
- data/lib/flexmls_api/cli.rb +51 -25
- data/lib/flexmls_api/cli/oauth2.rb +1 -30
- data/lib/flexmls_api/cli/setup.rb +4 -1
- data/lib/flexmls_api/client.rb +1 -1
- data/lib/flexmls_api/configuration.rb +10 -0
- data/lib/flexmls_api/configuration/yaml.rb +81 -0
- data/lib/flexmls_api/faraday.rb +12 -2
- data/lib/flexmls_api/models.rb +25 -23
- data/lib/flexmls_api/models/constraint.rb +16 -0
- data/lib/flexmls_api/models/listing.rb +45 -2
- data/lib/flexmls_api/models/photo.rb +57 -2
- data/lib/flexmls_api/models/subresource.rb +5 -2
- data/lib/flexmls_api/multi_client.rb +21 -6
- data/lib/flexmls_api/paginate.rb +18 -1
- data/lib/flexmls_api/request.rb +1 -71
- data/lib/flexmls_api/response.rb +69 -0
- data/spec/fixtures/{contacts.json → contacts/contacts.json} +0 -0
- data/spec/fixtures/{contact_my.json → contacts/my.json} +0 -0
- data/spec/fixtures/{contact_new.json → contacts/new.json} +0 -0
- data/spec/fixtures/{contact_new_empty.json → contacts/new_empty.json} +0 -0
- data/spec/fixtures/{contact_new_notify.json → contacts/new_notify.json} +0 -0
- data/spec/fixtures/{contacts_post.json → contacts/post.json} +0 -0
- data/spec/fixtures/{contact_tags.json → contacts/tags.json} +0 -0
- data/spec/fixtures/{listing_cart_add_listing.json → listing_carts/add_listing.json} +0 -0
- data/spec/fixtures/{listing_cart_add_listing_post.json → listing_carts/add_listing_post.json} +0 -0
- data/spec/fixtures/{listing_cart_empty.json → listing_carts/empty.json} +0 -0
- data/spec/fixtures/{listing_cart.json → listing_carts/listing_cart.json} +0 -0
- data/spec/fixtures/{listing_cart_new.json → listing_carts/new.json} +0 -0
- data/spec/fixtures/{listing_cart_post.json → listing_carts/post.json} +0 -0
- data/spec/fixtures/{listing_cart_remove_listing.json → listing_carts/remove_listing.json} +0 -0
- data/spec/fixtures/listings/constraints.json +18 -0
- data/spec/fixtures/listings/constraints_with_pagination.json +24 -0
- data/spec/fixtures/{listing_document_index.json → listings/document_index.json} +0 -0
- data/spec/fixtures/{listing_no_subresources.json → listings/no_subresources.json} +0 -0
- data/spec/fixtures/{open_houses.json → listings/open_houses.json} +0 -0
- data/spec/fixtures/{listing_photos_index.json → listings/photos/index.json} +0 -0
- data/spec/fixtures/listings/photos/new.json +12 -0
- data/spec/fixtures/listings/photos/post.json +20 -0
- data/spec/fixtures/listings/put.json +5 -0
- data/spec/fixtures/{saved_search.json → listings/saved_search.json} +0 -0
- data/spec/fixtures/{shared_listing_new.json → listings/shared_listing_new.json} +0 -0
- data/spec/fixtures/{shared_listing_post.json → listings/shared_listing_post.json} +0 -0
- data/spec/fixtures/{tour_of_homes.json → listings/tour_of_homes.json} +0 -0
- data/spec/fixtures/{listing_videos_index.json → listings/videos_index.json} +0 -0
- data/spec/fixtures/{listing_virtual_tours_index.json → listings/virtual_tours_index.json} +0 -0
- data/spec/fixtures/{listing_with_documents.json → listings/with_documents.json} +0 -0
- data/spec/fixtures/listings/with_permissions.json +44 -0
- data/spec/fixtures/{listing_with_photos.json → listings/with_photos.json} +0 -0
- data/spec/fixtures/{listing_with_supplement.json → listings/with_supplement.json} +0 -0
- data/spec/fixtures/{listing_with_videos.json → listings/with_videos.json} +0 -0
- data/spec/fixtures/{listing_with_vtour.json → listings/with_vtour.json} +0 -0
- data/spec/fixtures/logo_fbs.png +0 -0
- data/spec/fixtures/{add_note.json → notes/add.json} +0 -0
- data/spec/fixtures/{agent_shared_note.json → notes/agent_shared.json} +0 -0
- data/spec/fixtures/{agent_shared_note_empty.json → notes/agent_shared_empty.json} +0 -0
- data/spec/fixtures/{note_new.json → notes/new.json} +0 -0
- data/spec/fixtures/{standardfields_city.json → standardfields/city.json} +0 -0
- data/spec/fixtures/{standardfields_nearby.json → standardfields/nearby.json} +0 -0
- data/spec/fixtures/{standardfields.json → standardfields/standardfields.json} +0 -0
- data/spec/fixtures/{standardfields_stateorprovince.json → standardfields/stateorprovince.json} +0 -0
- data/spec/mock_helper.rb +5 -3
- data/spec/unit/flexmls_api/authentication/api_auth_spec.rb +11 -2
- data/spec/unit/flexmls_api/authentication/base_auth_spec.rb +10 -0
- data/spec/unit/flexmls_api/authentication/oauth2_spec.rb +3 -3
- data/spec/unit/flexmls_api/configuration/yaml_spec.rb +70 -0
- data/spec/unit/flexmls_api/models/constraint_spec.rb +19 -0
- data/spec/unit/flexmls_api/models/contact_spec.rb +8 -8
- data/spec/unit/flexmls_api/models/document_spec.rb +1 -1
- data/spec/unit/flexmls_api/models/listing_cart_spec.rb +15 -15
- data/spec/unit/flexmls_api/models/listing_spec.rb +78 -13
- data/spec/unit/flexmls_api/models/note_spec.rb +4 -4
- data/spec/unit/flexmls_api/models/open_house_spec.rb +1 -1
- data/spec/unit/flexmls_api/models/photo_spec.rb +73 -40
- data/spec/unit/flexmls_api/models/saved_search_spec.rb +3 -3
- data/spec/unit/flexmls_api/models/shared_listing_spec.rb +1 -1
- data/spec/unit/flexmls_api/models/standard_fields_spec.rb +4 -7
- data/spec/unit/flexmls_api/models/tour_of_home_spec.rb +1 -1
- data/spec/unit/flexmls_api/models/video_spec.rb +1 -1
- data/spec/unit/flexmls_api/models/virtual_tour_spec.rb +1 -1
- data/spec/unit/flexmls_api/multi_client_spec.rb +9 -1
- data/spec/unit/flexmls_api/paginate_spec.rb +1 -1
- data/spec/unit/flexmls_api/request_spec.rb +2 -2
- metadata +182 -152
data/History.txt
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
== v0.7.0 2011-10-03
|
2
|
+
* Major changes to results object returned from the client (and models). Results are no longer allowed to be nil, and Array is decorated with non result response information.
|
3
|
+
* Finished listing photo uploads
|
4
|
+
* ListPrice save operation for listings
|
5
|
+
* Listing contraints processing
|
6
|
+
== v0.6.7 2011-09-02
|
7
|
+
* YAML key management
|
8
|
+
== v0.6.6 2011-08-30
|
9
|
+
* Added methods for returning street, region, and full address for a listing
|
10
|
+
== v0.6.5 2011-08-02
|
11
|
+
* Fixed some recursive gemspec issues from jewler by removing jeweler and going with some of our own custom rake tasks.
|
1
12
|
== v0.6.4 2011-08-02
|
2
13
|
* added public method for the listing carts service specified
|
3
14
|
* added spec for portal listing cart method
|
@@ -121,4 +132,4 @@
|
|
121
132
|
== v0.1.1 2010-12-23
|
122
133
|
* IDX link and market stat models.
|
123
134
|
== v0.1.0 2010-12-13
|
124
|
-
* Initial usable release with request interface and models
|
135
|
+
* Initial usable release with request interface and models
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/lib/flexmls_api.rb
CHANGED
@@ -1,24 +1,25 @@
|
|
1
|
-
# Flexmlsapi
|
2
1
|
require 'rubygems'
|
3
2
|
require 'curb'
|
4
3
|
require 'json'
|
5
4
|
require 'logger'
|
6
5
|
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
6
|
+
require 'flexmls_api/version'
|
7
|
+
require 'flexmls_api/configuration'
|
8
|
+
require 'flexmls_api/multi_client'
|
9
|
+
require 'flexmls_api/authentication'
|
10
|
+
require 'flexmls_api/response'
|
11
|
+
require 'flexmls_api/paginate'
|
12
|
+
require 'flexmls_api/request'
|
13
|
+
require 'flexmls_api/client'
|
14
|
+
require 'flexmls_api/faraday'
|
15
|
+
require 'flexmls_api/primary_array'
|
16
|
+
require 'flexmls_api/models'
|
17
17
|
|
18
18
|
module FlexmlsApi
|
19
19
|
extend Configuration
|
20
20
|
extend MultiClient
|
21
21
|
|
22
|
+
#:nocov:
|
22
23
|
def self.logger
|
23
24
|
if @logger.nil?
|
24
25
|
@logger = Logger.new(STDOUT)
|
@@ -26,6 +27,7 @@ module FlexmlsApi
|
|
26
27
|
end
|
27
28
|
@logger
|
28
29
|
end
|
30
|
+
#:nocov:
|
29
31
|
|
30
32
|
def self.client(opts={})
|
31
33
|
Thread.current[:flexmls_api_client] ||= FlexmlsApi::Client.new(opts)
|
@@ -12,7 +12,7 @@ module FlexmlsApi
|
|
12
12
|
class ApiAuth < BaseAuth
|
13
13
|
|
14
14
|
def initialize(client)
|
15
|
-
|
15
|
+
super(client)
|
16
16
|
end
|
17
17
|
|
18
18
|
def authenticate
|
@@ -55,14 +55,16 @@ module FlexmlsApi
|
|
55
55
|
|
56
56
|
# Sign a request with request data.
|
57
57
|
def sign_token(path, params = {}, post_data="")
|
58
|
-
|
58
|
+
token_string = "#{@client.api_secret}ApiKey#{@client.api_key}ServicePath#{path}#{build_param_string(params)}#{post_data}"
|
59
|
+
signed = sign(token_string)
|
60
|
+
signed
|
59
61
|
end
|
60
62
|
|
61
63
|
# Perform an HTTP request (no data)
|
62
64
|
def request(method, path, body, options)
|
63
65
|
escaped_path = URI.escape(path)
|
64
66
|
request_opts = {
|
65
|
-
|
67
|
+
:AuthToken => @session.auth_token
|
66
68
|
}
|
67
69
|
unless @client.api_user.nil?
|
68
70
|
request_opts.merge!(:ApiUser => "#{@client.api_user}")
|
@@ -5,14 +5,6 @@ module FlexmlsApi
|
|
5
5
|
|
6
6
|
module Authentication
|
7
7
|
|
8
|
-
module OAuth2Impl
|
9
|
-
require 'flexmls_api/authentication/oauth2_impl/middleware'
|
10
|
-
require 'flexmls_api/authentication/oauth2_impl/grant_type_base'
|
11
|
-
require 'flexmls_api/authentication/oauth2_impl/grant_type_refresh'
|
12
|
-
require 'flexmls_api/authentication/oauth2_impl/grant_type_code'
|
13
|
-
require 'flexmls_api/authentication/oauth2_impl/grant_type_password'
|
14
|
-
end
|
15
|
-
|
16
8
|
#=OAuth2 Authentication
|
17
9
|
# Auth implementation to the API using the OAuth2 service endpoint. Current adheres to the 10
|
18
10
|
# draft of the OAuth2 specification. With OAuth2, the application supplies credentials for the
|
@@ -30,7 +22,7 @@ module FlexmlsApi
|
|
30
22
|
class OAuth2 < BaseAuth
|
31
23
|
|
32
24
|
def initialize(client)
|
33
|
-
|
25
|
+
super(client)
|
34
26
|
@provider = client.oauth2_provider
|
35
27
|
end
|
36
28
|
|
@@ -120,18 +112,23 @@ module FlexmlsApi
|
|
120
112
|
# @client_id - OAuth2 provided application identifier
|
121
113
|
# @client_secret - OAuth2 provided password for the client id
|
122
114
|
class BaseOAuth2Provider
|
123
|
-
|
124
|
-
attr_accessor :authorization_uri, :access_uri, :grant_type, :client_id, :client_secret
|
125
|
-
|
115
|
+
attr_accessor *Configuration::OAUTH2_KEYS
|
126
116
|
# Requirements for authorization_code grant type
|
127
|
-
attr_accessor :code
|
128
|
-
|
129
|
-
|
117
|
+
attr_accessor :code
|
118
|
+
attr_accessor :grant_type
|
119
|
+
|
120
|
+
def initialize(opts={})
|
121
|
+
Configuration::OAUTH2_KEYS.each do |key|
|
122
|
+
send("#{key}=", opts[key]) if opts.include? key
|
123
|
+
end
|
124
|
+
@grant_type = :authorization_code
|
125
|
+
end
|
130
126
|
|
131
127
|
def grant_type
|
132
|
-
|
128
|
+
# backwards compatibility check
|
129
|
+
@grant_type.nil? ? :authorization_code : @grant_type
|
133
130
|
end
|
134
|
-
|
131
|
+
|
135
132
|
# Application using the client must handle user redirect for user authentication. For
|
136
133
|
# command line applications, this method is called prior to initial client requests so that
|
137
134
|
# the process can notify the user to go to the url and retrieve the access_code for the app.
|
@@ -166,6 +163,15 @@ module FlexmlsApi
|
|
166
163
|
|
167
164
|
end
|
168
165
|
|
166
|
+
module OAuth2Impl
|
167
|
+
require 'flexmls_api/authentication/oauth2_impl/middleware'
|
168
|
+
require 'flexmls_api/authentication/oauth2_impl/grant_type_base'
|
169
|
+
require 'flexmls_api/authentication/oauth2_impl/grant_type_refresh'
|
170
|
+
require 'flexmls_api/authentication/oauth2_impl/grant_type_code'
|
171
|
+
require 'flexmls_api/authentication/oauth2_impl/grant_type_password'
|
172
|
+
require 'flexmls_api/authentication/oauth2_impl/password_provider'
|
173
|
+
end
|
174
|
+
|
169
175
|
end
|
170
176
|
|
171
177
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
module FlexmlsApi
|
3
|
+
module Authentication
|
4
|
+
module OAuth2Impl
|
5
|
+
class PasswordProvider < FlexmlsApi::Authentication::BaseOAuth2Provider
|
6
|
+
def initialize(credentials)
|
7
|
+
super(credentials)
|
8
|
+
@grant_type = :password
|
9
|
+
end
|
10
|
+
|
11
|
+
def load_session()
|
12
|
+
@session
|
13
|
+
end
|
14
|
+
|
15
|
+
def save_session(session)
|
16
|
+
@session = session
|
17
|
+
end
|
18
|
+
|
19
|
+
def destroy_session
|
20
|
+
@session = nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/flexmls_api/cli.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
require 'optparse'
|
2
2
|
|
3
|
+
if ENV["FLEXMLS_API_CONSOLE"].nil?
|
4
|
+
require 'flexmls_api'
|
5
|
+
else
|
6
|
+
puts "Enabling console mode for local gem"
|
7
|
+
Bundler.require(:default, "development") if defined?(Bundler)
|
8
|
+
path = File.expand_path(File.dirname(__FILE__) + "/../../../lib/")
|
9
|
+
$LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
|
10
|
+
require path + '/flexmls_api'
|
11
|
+
end
|
12
|
+
|
3
13
|
module FlexmlsApi
|
4
14
|
module CLI
|
5
15
|
class ConsoleCLI
|
@@ -16,7 +26,7 @@ module FlexmlsApi
|
|
16
26
|
:api_secret => "API_SECRET",
|
17
27
|
:api_user => "API_USER",
|
18
28
|
# OTHER
|
19
|
-
:
|
29
|
+
:debug=> "DEBUG",
|
20
30
|
:console => "FLEXMLS_API_CONSOLE" # not a public option, meant to distinguish bin/flexmls_api and script/console
|
21
31
|
}
|
22
32
|
|
@@ -38,7 +48,7 @@ module FlexmlsApi
|
|
38
48
|
|
39
49
|
private
|
40
50
|
def self.setup_options(stdout,arguments)
|
41
|
-
|
51
|
+
env_options = {
|
42
52
|
:oauth2 => false,
|
43
53
|
:endpoint => ENV[OPTIONS_ENV[:endpoint]],
|
44
54
|
# OAUTH2 Options
|
@@ -53,9 +63,11 @@ module FlexmlsApi
|
|
53
63
|
:api_user => ENV[OPTIONS_ENV[:api_user]],
|
54
64
|
:console => ENV[OPTIONS_ENV[:console]]
|
55
65
|
}
|
56
|
-
|
66
|
+
cli_options = {}
|
67
|
+
file_options = {}
|
57
68
|
parser = OptionParser.new do |opts|
|
58
69
|
opts.banner = <<-BANNER.gsub(/^ /,'')
|
70
|
+
#{version}
|
59
71
|
FlexmlsApi Client Console - http://www.flexmls.com/developers/api/
|
60
72
|
|
61
73
|
Usage: #{File.basename($0)} [options]
|
@@ -68,47 +80,51 @@ module FlexmlsApi
|
|
68
80
|
opts.on("-o","--oauth2",
|
69
81
|
"Run the API using OAuth2 credentials. The client defaults to using the flexmls API authentication mode for access. ",
|
70
82
|
"See http://www.flexmls.com/developers/api/api-services/authentication/ for more information on authentication types.",
|
71
|
-
"Default: false") { |arg|
|
72
|
-
opts.on("-e","--endpoint",
|
83
|
+
"Default: false") { |arg| cli_options[:oauth2] = arg }
|
84
|
+
opts.on("-e","--endpoint ENDPOINT",
|
73
85
|
"URI of the API.",
|
74
|
-
"Default: ENV['#{OPTIONS_ENV[:endpoint]}']") { |arg|
|
86
|
+
"Default: ENV['#{OPTIONS_ENV[:endpoint]}']") { |arg| cli_options[:endpoint] = arg }
|
75
87
|
|
76
88
|
# OAUTH2
|
77
|
-
opts.on("--client_id",
|
89
|
+
opts.on("--client_id CLIENT_ID",
|
78
90
|
"OAuth2 client id",
|
79
|
-
"Default: ENV['#{OPTIONS_ENV[:client_id]}']") { |arg|
|
80
|
-
opts.on("--client_secret",
|
91
|
+
"Default: ENV['#{OPTIONS_ENV[:client_id]}']") { |arg| cli_options[:client_id] = arg }
|
92
|
+
opts.on("--client_secret CLIENT_SECRET",
|
81
93
|
"OAuth2 client secret",
|
82
|
-
"Default: ENV['#{OPTIONS_ENV[:client_secret]}']") { |arg|
|
83
|
-
opts.on("-u","--username",
|
94
|
+
"Default: ENV['#{OPTIONS_ENV[:client_secret]}']") { |arg| cli_options[:client_secret] = arg }
|
95
|
+
opts.on("-u","--username USERNAME",
|
84
96
|
"OAuth2 username",
|
85
|
-
"Default: ENV['#{OPTIONS_ENV[:username]}']") { |arg|
|
86
|
-
opts.on("-p","--password",
|
97
|
+
"Default: ENV['#{OPTIONS_ENV[:username]}']") { |arg| cli_options[:username] = arg }
|
98
|
+
opts.on("-p","--password PASSWORD",
|
87
99
|
"OAuth2 password",
|
88
|
-
"Default: ENV['#{OPTIONS_ENV[:password]}']") { |arg|
|
89
|
-
opts.on("--access_uri",
|
100
|
+
"Default: ENV['#{OPTIONS_ENV[:password]}']") { |arg| cli_options[:password] = arg }
|
101
|
+
opts.on("--access_uri ACCESS_URI",
|
90
102
|
"OAuth2 path for granting access to the application",
|
91
|
-
"Default: ENV['#{OPTIONS_ENV[:access_uri]}']") { |arg|
|
103
|
+
"Default: ENV['#{OPTIONS_ENV[:access_uri]}']") { |arg| cli_options[:access_uri] = arg }
|
92
104
|
|
93
105
|
# API AUTH
|
94
|
-
opts.on("--api_key",
|
106
|
+
opts.on("--api_key API_KEY",
|
95
107
|
"Authentication key for running the api using the default api authentication",
|
96
|
-
"Default: ENV['#{OPTIONS_ENV[:api_key]}']") { |arg|
|
97
|
-
opts.on("--api_secret",
|
108
|
+
"Default: ENV['#{OPTIONS_ENV[:api_key]}']") { |arg| cli_options[:api_key] = arg }
|
109
|
+
opts.on("--api_secret API_SECRET",
|
98
110
|
"API secret for the api key",
|
99
|
-
"Default: ENV['#{OPTIONS_ENV[:api_secret]}']") { |arg|
|
100
|
-
opts.on("--api_user",
|
111
|
+
"Default: ENV['#{OPTIONS_ENV[:api_secret]}']") { |arg| cli_options[:api_secret] = arg }
|
112
|
+
opts.on("--api_user API_USER",
|
101
113
|
"ID of the flexmls user to run the client as.",
|
102
|
-
"Default: ENV['#{OPTIONS_ENV[:api_user]}']") { |arg|
|
114
|
+
"Default: ENV['#{OPTIONS_ENV[:api_user]}']") { |arg| cli_options[:api_user] = arg }
|
103
115
|
|
104
|
-
opts.on("-
|
105
|
-
"
|
116
|
+
opts.on("-f", "--file FILE",
|
117
|
+
"Load configuration for yaml file.") { |arg| file_options = parse_file_options(arg) }
|
118
|
+
opts.on("-d", "--debug",
|
119
|
+
"Show detailed request logging information.") { |arg| cli_options[:debug] = arg }
|
120
|
+
opts.on("-v", "--version",
|
121
|
+
"Show client version.") { stdout.puts version; exit }
|
106
122
|
opts.on("-h", "--help",
|
107
123
|
"Show this help message.") { stdout.puts opts; exit }
|
108
124
|
opts.parse!(arguments)
|
109
125
|
|
110
126
|
end
|
111
|
-
|
127
|
+
options = env_options.merge(file_options.merge(cli_options))
|
112
128
|
return options
|
113
129
|
end
|
114
130
|
|
@@ -127,6 +143,16 @@ module FlexmlsApi
|
|
127
143
|
end
|
128
144
|
run_env
|
129
145
|
end
|
146
|
+
|
147
|
+
private
|
148
|
+
def self.parse_file_options(file)
|
149
|
+
yaml = FlexmlsApi::Configuration::YamlConfig.new(file)
|
150
|
+
return {:oauth2 => yaml.oauth2}.merge(yaml.client_keys.merge(yaml.oauth2_keys))
|
151
|
+
end
|
152
|
+
|
153
|
+
def self.version
|
154
|
+
"flexmlsApi v#{FlexmlsApi::VERSION}"
|
155
|
+
end
|
130
156
|
end
|
131
157
|
end
|
132
158
|
end
|
@@ -1,36 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/../cli/setup"
|
2
2
|
|
3
|
-
class CLIOAuth2Provider < FlexmlsApi::Authentication::BaseOAuth2Provider
|
4
|
-
def initialize(credentials)
|
5
|
-
@authorization_uri = credentials[:authorization_uri]
|
6
|
-
@access_uri = credentials[:access_uri]
|
7
|
-
@redirect_uri = credentials[:redirect_uri]
|
8
|
-
@client_id = credentials[:client_id]
|
9
|
-
@client_secret = credentials[:client_secret]
|
10
|
-
@username = credentials[:username]
|
11
|
-
@password = credentials[:password]
|
12
|
-
@session = nil
|
13
|
-
end
|
14
|
-
|
15
|
-
def grant_type
|
16
|
-
:password
|
17
|
-
end
|
18
|
-
|
19
|
-
def load_session()
|
20
|
-
@session
|
21
|
-
end
|
22
|
-
|
23
|
-
def save_session(session)
|
24
|
-
@session = session
|
25
|
-
end
|
26
|
-
|
27
|
-
def destroy_session
|
28
|
-
@session = nil
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
3
|
FlexmlsApi.configure do |config|
|
33
|
-
config.oauth2_provider =
|
4
|
+
config.oauth2_provider = FlexmlsApi::Authentication::OAuth2Impl::PasswordProvider.new(
|
34
5
|
:authorization_uri=> ENV["AUTH_URI"],
|
35
6
|
:access_uri => ENV["ACCESS_URI"],
|
36
7
|
:username=> ENV["USERNAME"],
|
@@ -1,5 +1,8 @@
|
|
1
1
|
require "rubygems"
|
2
2
|
require 'pp'
|
3
|
+
require 'irb/ext/save-history'
|
4
|
+
IRB.conf[:SAVE_HISTORY] = 1000
|
5
|
+
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.flexmls-api-history"
|
3
6
|
|
4
7
|
if ENV["FLEXMLS_API_CONSOLE"].nil?
|
5
8
|
require 'flexmls_api'
|
@@ -29,7 +32,7 @@ module FlexmlsApi
|
|
29
32
|
def self.logger
|
30
33
|
if @logger.nil?
|
31
34
|
@logger = Logger.new(STDOUT)
|
32
|
-
@logger.level = ENV["
|
35
|
+
@logger.level = ENV["DEBUG"].nil? ? Logger::WARN : Logger::DEBUG
|
33
36
|
end
|
34
37
|
@logger
|
35
38
|
end
|
data/lib/flexmls_api/client.rb
CHANGED
@@ -1,7 +1,17 @@
|
|
1
|
+
|
1
2
|
module FlexmlsApi
|
2
3
|
module Configuration
|
4
|
+
|
3
5
|
# valid configuration options
|
4
6
|
VALID_OPTION_KEYS = [:api_key, :api_secret, :api_user, :endpoint, :user_agent, :version, :ssl, :oauth2_provider, :authentication_mode].freeze
|
7
|
+
OAUTH2_KEYS = [:authorization_uri, :access_uri, :client_id, :client_secret,
|
8
|
+
# Requirements for authorization_code grant type
|
9
|
+
:redirect_uri,
|
10
|
+
# Requirements for password grant type
|
11
|
+
:username, :password
|
12
|
+
]
|
13
|
+
|
14
|
+
require File.expand_path('../configuration/yaml', __FILE__)
|
5
15
|
|
6
16
|
DEFAULT_API_KEY = nil
|
7
17
|
DEFAULT_API_SECRET = nil
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'erb'
|
2
|
+
module FlexmlsApi
|
3
|
+
module Configuration
|
4
|
+
class YamlConfig
|
5
|
+
KEY_CONFIGURATIONS = VALID_OPTION_KEYS + [:oauth2] + OAUTH2_KEYS
|
6
|
+
|
7
|
+
attr_accessor *KEY_CONFIGURATIONS
|
8
|
+
attr_reader :client_keys, :oauth2_keys
|
9
|
+
|
10
|
+
def initialize(filename=nil)
|
11
|
+
@client_keys = {}
|
12
|
+
@oauth2_keys = {}
|
13
|
+
@oauth2 = false
|
14
|
+
load_file(filename) unless filename.nil?()
|
15
|
+
end
|
16
|
+
def load_file(file)
|
17
|
+
@client_keys = {}
|
18
|
+
@oauth2_keys = {}
|
19
|
+
@file = file
|
20
|
+
@name = File.basename(file, ".yml")
|
21
|
+
config = YAML.load(ERB.new(File.read(file)).result)[api_env]
|
22
|
+
config.each do |key,val|
|
23
|
+
sym = key.to_sym
|
24
|
+
if KEY_CONFIGURATIONS.include? sym
|
25
|
+
self.send("#{sym}=", val)
|
26
|
+
if VALID_OPTION_KEYS.include?(sym)
|
27
|
+
@client_keys[sym] = val
|
28
|
+
elsif OAUTH2_KEYS.include?(sym)
|
29
|
+
@oauth2_keys[sym] = val
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
rescue => e
|
34
|
+
FlexmlsApi.logger().error("Unable to load config file #{file}[#{api_env}]")
|
35
|
+
raise e
|
36
|
+
end
|
37
|
+
|
38
|
+
def oauth2?
|
39
|
+
return oauth2 == true
|
40
|
+
end
|
41
|
+
|
42
|
+
def name
|
43
|
+
@name
|
44
|
+
end
|
45
|
+
def api_env
|
46
|
+
current_env = "development"
|
47
|
+
if env.include?("FLEXMLS_API_ENV")
|
48
|
+
current_env = env["FLEXMLS_API_ENV"]
|
49
|
+
elsif env.include?("RAILS_ENV")
|
50
|
+
current_env = env["RAILS_ENV"]
|
51
|
+
end
|
52
|
+
return current_env
|
53
|
+
end
|
54
|
+
|
55
|
+
# Used to specify the root of where to look for flexmlsApi config files
|
56
|
+
def self.config_path
|
57
|
+
"config/flexmls_api"
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.config_keys()
|
61
|
+
files = Dir["#{config_path}/*.yml"]
|
62
|
+
files.map {|f| File.basename(f,".yml") }
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.exists?(name)
|
66
|
+
File.exists? "#{config_path}/#{name}.yml"
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.build(name)
|
70
|
+
yaml = YamlConfig.new("#{config_path}/#{name}.yml")
|
71
|
+
end
|
72
|
+
|
73
|
+
protected
|
74
|
+
def env
|
75
|
+
ENV
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|