spark_api 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/README.md +86 -3
  2. data/VERSION +1 -1
  3. data/lib/spark_api.rb +1 -0
  4. data/lib/spark_api/authentication/oauth2.rb +43 -2
  5. data/lib/spark_api/configuration/oauth2_configurable.rb +3 -1
  6. data/lib/spark_api/models.rb +1 -0
  7. data/lib/spark_api/models/listing.rb +17 -1
  8. data/lib/spark_api/models/rental_calendar.rb +26 -0
  9. data/lib/spark_api/options_hash.rb +18 -0
  10. data/script/combined_flow_example.rb +55 -0
  11. data/script/oauth2_example.rb +2 -2
  12. data/spec/fixtures/listings/rental_calendar.json +19 -0
  13. data/spec/fixtures/listings/with_rental_calendar.json +52 -0
  14. data/spec/unit/spark_api/authentication/oauth2_spec.rb +79 -1
  15. data/spec/unit/spark_api/models/listing_spec.rb +7 -0
  16. data/spec/unit/spark_api/models/rental_calendar_spec.rb +30 -0
  17. data/spec/unit/spark_api/options_hash_spec.rb +14 -0
  18. metadata +15 -96
  19. data/bin/spark_api~ +0 -8
  20. data/lib/spark_api/authentication/api_auth.rb~ +0 -104
  21. data/lib/spark_api/authentication/base_auth.rb~ +0 -47
  22. data/lib/spark_api/authentication/oauth2.rb~ +0 -199
  23. data/lib/spark_api/authentication/oauth2_impl/grant_type_base.rb~ +0 -87
  24. data/lib/spark_api/authentication/oauth2_impl/grant_type_code.rb~ +0 -49
  25. data/lib/spark_api/authentication/oauth2_impl/grant_type_password.rb~ +0 -45
  26. data/lib/spark_api/authentication/oauth2_impl/grant_type_refresh.rb~ +0 -36
  27. data/lib/spark_api/authentication/oauth2_impl/middleware.rb~ +0 -39
  28. data/lib/spark_api/authentication/oauth2_impl/password_provider.rb~ +0 -25
  29. data/lib/spark_api/cli.rb~ +0 -158
  30. data/lib/spark_api/cli/api_auth.rb~ +0 -8
  31. data/lib/spark_api/cli/oauth2.rb~ +0 -14
  32. data/lib/spark_api/cli/setup.rb~ +0 -47
  33. data/lib/spark_api/configuration.rb~ +0 -54
  34. data/lib/spark_api/configuration/yaml.rb~ +0 -101
  35. data/lib/spark_api/faraday.rb~ +0 -64
  36. data/lib/spark_api/models.rb~ +0 -33
  37. data/lib/spark_api/models/account.rb~ +0 -115
  38. data/lib/spark_api/models/base.rb~ +0 -118
  39. data/lib/spark_api/models/connect_prefs.rb~ +0 -10
  40. data/lib/spark_api/models/constraint.rb~ +0 -16
  41. data/lib/spark_api/models/contact.rb~ +0 -49
  42. data/lib/spark_api/models/custom_fields.rb~ +0 -12
  43. data/lib/spark_api/models/document.rb~ +0 -11
  44. data/lib/spark_api/models/finders.rb~ +0 -45
  45. data/lib/spark_api/models/idx_link.rb~ +0 -47
  46. data/lib/spark_api/models/listing.rb~ +0 -197
  47. data/lib/spark_api/models/listing_cart.rb~ +0 -72
  48. data/lib/spark_api/models/market_statistics.rb~ +0 -33
  49. data/lib/spark_api/models/message.rb~ +0 -21
  50. data/lib/spark_api/models/note.rb~ +0 -41
  51. data/lib/spark_api/models/notification.rb~ +0 -42
  52. data/lib/spark_api/models/open_house.rb~ +0 -24
  53. data/lib/spark_api/models/photo.rb~ +0 -70
  54. data/lib/spark_api/models/property_types.rb~ +0 -7
  55. data/lib/spark_api/models/saved_search.rb~ +0 -16
  56. data/lib/spark_api/models/shared_listing.rb~ +0 -35
  57. data/lib/spark_api/models/standard_fields.rb~ +0 -50
  58. data/lib/spark_api/models/subresource.rb~ +0 -19
  59. data/lib/spark_api/models/system_info.rb~ +0 -14
  60. data/lib/spark_api/models/tour_of_home.rb~ +0 -24
  61. data/lib/spark_api/models/video.rb~ +0 -16
  62. data/lib/spark_api/models/virtual_tour.rb~ +0 -18
  63. data/lib/spark_api/multi_client.rb~ +0 -59
  64. data/lib/spark_api/paginate.rb~ +0 -109
  65. data/lib/spark_api/primary_array.rb~ +0 -29
  66. data/lib/spark_api/request.rb~ +0 -96
  67. data/lib/spark_api/response.rb~ +0 -70
  68. data/lib/spark_api/version.rb~ +0 -4
  69. data/script/console~ +0 -6
  70. data/script/example.rb~ +0 -27
  71. data/spec/unit/flexmls_api_spec.rb~ +0 -23
  72. data/spec/unit/spark_api/authentication/api_auth_spec.rb~ +0 -169
  73. data/spec/unit/spark_api/authentication/base_auth_spec.rb~ +0 -10
  74. data/spec/unit/spark_api/authentication/oauth2_impl/grant_type_base_spec.rb~ +0 -10
  75. data/spec/unit/spark_api/authentication/oauth2_spec.rb~ +0 -205
  76. data/spec/unit/spark_api/authentication_spec.rb~ +0 -38
  77. data/spec/unit/spark_api/configuration/yaml_spec.rb~ +0 -72
  78. data/spec/unit/spark_api/configuration_spec.rb~ +0 -122
  79. data/spec/unit/spark_api/faraday_spec.rb~ +0 -90
  80. data/spec/unit/spark_api/models/contact_spec.rb~ +0 -108
  81. data/spec/unit/spark_api/models/listing_cart_spec.rb~ +0 -127
  82. data/spec/unit/spark_api/models/listing_spec.rb~ +0 -320
  83. data/spec/unit/spark_api/models/message_spec.rb~ +0 -47
  84. data/spec/unit/spark_api/models/note_spec.rb~ +0 -63
  85. data/spec/unit/spark_api/models/notification_spec.rb~ +0 -62
  86. data/spec/unit/spark_api/models/shared_listing_spec.rb~ +0 -45
  87. data/spec/unit/spark_api/multi_client_spec.rb~ +0 -56
  88. data/spec/unit/spark_api/paginate_spec.rb~ +0 -224
  89. data/spec/unit/spark_api/primary_array_spec.rb~ +0 -41
  90. data/spec/unit/spark_api/request_spec.rb~ +0 -344
@@ -1,45 +0,0 @@
1
-
2
- module FlexmlsApi
3
- module Authentication
4
- module OAuth2Impl
5
- # OAuth2 authentication flow using username and password parameters for the user in the
6
- # request. This implementation is geared towards authentication styles for native
7
- # applications that need to use OAuth2
8
- class GrantTypePassword < GrantTypeBase
9
- def initialize(client, provider, session)
10
- super(client, provider, session)
11
- end
12
- def authenticate
13
- new_session = nil
14
- if needs_refreshing?
15
- new_session = refresh
16
- end
17
- return new_session unless new_session.nil?
18
- create_session(token_params)
19
- end
20
-
21
- def refresh()
22
- GrantTypeRefresh.new(client,provider,session).authenticate
23
- rescue ClientError => e
24
- FlexmlsApi.logger.info("[oauth2] Refreshing token failed, the library will try and authenticate from scratch: #{e.message}")
25
- nil
26
- end
27
-
28
- private
29
- def token_params
30
- params = {
31
- "client_id" => @provider.client_id,
32
- "client_secret" => @provider.client_secret,
33
- "grant_type" => "password",
34
- "username" => @provider.username,
35
- "password" => @provider.password,
36
- }.to_json
37
- end
38
- end
39
- end
40
- end
41
- end
42
-
43
-
44
-
45
-
@@ -1,36 +0,0 @@
1
-
2
- module FlexmlsApi
3
- module Authentication
4
- # OAuth2 authentication flow to refresh an access token
5
- module OAuth2Impl
6
- class GrantTypeRefresh < GrantTypeBase
7
- attr_accessor :params
8
- def initialize(client, provider, session)
9
- super(client, provider, session)
10
- @params = {}
11
- end
12
-
13
- def authenticate
14
- new_session = nil
15
- unless @session.refresh_token.nil?
16
- FlexmlsApi.logger.debug("[oauth2] Refreshing authentication to #{provider.access_uri} using [#{session.refresh_token}]")
17
- new_session = create_session(token_params)
18
- end
19
- new_session
20
- end
21
-
22
- private
23
- def token_params
24
- @params.merge({
25
- "client_id" => @provider.client_id,
26
- "client_secret" => @provider.client_secret,
27
- "grant_type" => "refresh_token",
28
- "refresh_token"=> session.refresh_token,
29
- }).to_json
30
- end
31
- end
32
-
33
- end
34
- end
35
- end
36
-
@@ -1,39 +0,0 @@
1
-
2
- module FlexmlsApi
3
-
4
- module Authentication
5
-
6
- module OAuth2Impl
7
-
8
- #==OAuth2 Faraday response middleware
9
- # HTTP Response after filter to package oauth2 responses and bubble up basic api errors.
10
- class Middleware < Faraday::Response::ParseJson
11
- def on_complete(finished_env)
12
- body = parse(finished_env[:body])
13
- FlexmlsApi.logger.debug("[oauth2] Response Body: #{body.inspect}")
14
- unless body.is_a?(Hash)
15
- raise InvalidResponse, "The server response could not be understood"
16
- end
17
- case finished_env[:status]
18
- when 200..299
19
- FlexmlsApi.logger.debug("[oauth2] Success!")
20
- session = OAuthSession.new(body)
21
- else
22
- # Handle the WWW-Authenticate Response Header Field if present. This can be returned by
23
- # OAuth2 implementations and wouldn't hurt to log.
24
- auth_header_error = finished_env[:request_headers]["WWW-Authenticate"]
25
- FlexmlsApi.logger.warn("Authentication error #{auth_header_error}") unless auth_header_error.nil?
26
- raise ClientError, {:message => body["error"], :code =>0, :status => finished_env[:status]}
27
- end
28
- FlexmlsApi.logger.debug("[oauth2] Session=#{session.inspect}")
29
- finished_env[:body] = session
30
- end
31
-
32
- def initialize(app)
33
- super(app)
34
- end
35
-
36
- end
37
- end
38
- end
39
- end
@@ -1,25 +0,0 @@
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
@@ -1,158 +0,0 @@
1
- require 'optparse'
2
-
3
- if ENV["SPARK_API_CONSOLE"].nil?
4
- require 'spark_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 + '/spark_api'
11
- end
12
-
13
- module SparkApi
14
- module CLI
15
- class ConsoleCLI
16
- OPTIONS_ENV = {
17
- :endpoint => "API_ENDPOINT",
18
- # OAUTH2 Options
19
- :access_uri => "ACCESS_URI",
20
- :username=> "USERNAME",
21
- :password=> "PASSWORD",
22
- :client_id=> "CLIENT_ID",
23
- :client_secret=> "CLIENT_SECRET",
24
- # API AUTH Options
25
- :api_key => "API_KEY",
26
- :api_secret => "API_SECRET",
27
- :api_user => "API_USER",
28
- # OTHER
29
- :debug=> "DEBUG",
30
- :console => "SPARK_API_CONSOLE" # not a public option, meant to distinguish bin/spark_api and script/console
31
- }
32
-
33
- def self.execute(stdout, arguments=[])
34
- options = setup_options(stdout,arguments)
35
- libs = " -r irb/completion"
36
- # Perhaps use a console_lib to store any extra methods I may want available in the cosole
37
- libs << (options[:oauth2] ? setup_oauth2 : setup_api_auth)
38
-
39
- bundler = (options[:console] ? "bundle exec" : "")
40
- cmd = "#{export_env(options)} #{bundler} #{irb} #{libs} --simple-prompt"
41
- puts "Loading spark_api gem..."
42
- exec "#{cmd}"
43
- end
44
-
45
- def self.irb()
46
- RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
47
- end
48
-
49
- private
50
- def self.setup_options(stdout,arguments)
51
- env_options = {
52
- :oauth2 => false,
53
- :endpoint => ENV[OPTIONS_ENV[:endpoint]],
54
- # OAUTH2 Options
55
- :access_uri => ENV[OPTIONS_ENV[:access_uri]],
56
- :username=> ENV[OPTIONS_ENV[:username]],
57
- :password=> ENV[OPTIONS_ENV[:password]],
58
- :client_id=> ENV[OPTIONS_ENV[:client_id]],
59
- :client_secret=> ENV[OPTIONS_ENV[:client_secret]],
60
- # API AUTH Options
61
- :api_key => ENV[OPTIONS_ENV[:api_key]],
62
- :api_secret => ENV[OPTIONS_ENV[:api_secret]],
63
- :api_user => ENV[OPTIONS_ENV[:api_user]],
64
- :console => ENV[OPTIONS_ENV[:console]]
65
- }
66
- cli_options = {}
67
- file_options = {}
68
- parser = OptionParser.new do |opts|
69
- opts.banner = <<-BANNER.gsub(/^ /,'')
70
- #{version}
71
- SparkApi Client Console - http://www.flexmls.com/developers/api/
72
-
73
- Usage: #{File.basename($0)} [options]
74
-
75
- Environment Variables: some options (as indicated below), will default to values of keys set in the environment.
76
-
77
- Options are:
78
- BANNER
79
- opts.separator ""
80
- opts.on("-o","--oauth2",
81
- "Run the API using OAuth2 credentials. The client defaults to using the Spark API authentication mode for access. ",
82
- "See http://www.flexmls.com/developers/api/api-services/authentication/ for more information on authentication types.",
83
- "Default: false") { |arg| cli_options[:oauth2] = arg }
84
- opts.on("-e","--endpoint ENDPOINT",
85
- "URI of the API.",
86
- "Default: ENV['#{OPTIONS_ENV[:endpoint]}']") { |arg| cli_options[:endpoint] = arg }
87
-
88
- # OAUTH2
89
- opts.on("--client_id CLIENT_ID",
90
- "OAuth2 client id",
91
- "Default: ENV['#{OPTIONS_ENV[:client_id]}']") { |arg| cli_options[:client_id] = arg }
92
- opts.on("--client_secret CLIENT_SECRET",
93
- "OAuth2 client secret",
94
- "Default: ENV['#{OPTIONS_ENV[:client_secret]}']") { |arg| cli_options[:client_secret] = arg }
95
- opts.on("-u","--username USERNAME",
96
- "OAuth2 username",
97
- "Default: ENV['#{OPTIONS_ENV[:username]}']") { |arg| cli_options[:username] = arg }
98
- opts.on("-p","--password PASSWORD",
99
- "OAuth2 password",
100
- "Default: ENV['#{OPTIONS_ENV[:password]}']") { |arg| cli_options[:password] = arg }
101
- opts.on("--access_uri ACCESS_URI",
102
- "OAuth2 path for granting access to the application",
103
- "Default: ENV['#{OPTIONS_ENV[:access_uri]}']") { |arg| cli_options[:access_uri] = arg }
104
-
105
- # API AUTH
106
- opts.on("--api_key API_KEY",
107
- "Authentication key for running the api using the default api authentication",
108
- "Default: ENV['#{OPTIONS_ENV[:api_key]}']") { |arg| cli_options[:api_key] = arg }
109
- opts.on("--api_secret API_SECRET",
110
- "API secret for the api key",
111
- "Default: ENV['#{OPTIONS_ENV[:api_secret]}']") { |arg| cli_options[:api_secret] = arg }
112
- opts.on("--api_user API_USER",
113
- "ID of the Spark user to run the client as.",
114
- "Default: ENV['#{OPTIONS_ENV[:api_user]}']") { |arg| cli_options[:api_user] = arg }
115
-
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 }
122
- opts.on("-h", "--help",
123
- "Show this help message.") { stdout.puts opts; exit }
124
- opts.parse!(arguments)
125
-
126
- end
127
- options = env_options.merge(file_options.merge(cli_options))
128
- return options
129
- end
130
-
131
- def self.setup_api_auth
132
- " -r #{File.dirname(__FILE__) + '/../../lib/spark_api/cli/api_auth.rb'}"
133
- end
134
-
135
- def self.setup_oauth2
136
- " -r #{File.dirname(__FILE__) + '/../../lib/spark_api/cli/oauth2.rb'}"
137
- end
138
-
139
- def self.export_env(options)
140
- run_env = ""
141
- OPTIONS_ENV.each do |k,v|
142
- run_env << " #{v}=\"#{options[k]}\"" unless options[k].nil?
143
- end
144
- run_env
145
- end
146
-
147
- private
148
- def self.parse_file_options(file)
149
- yaml = SparkApi::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
- "SparkApi v#{SparkApi::VERSION}"
155
- end
156
- end
157
- end
158
- end
@@ -1,8 +0,0 @@
1
- require File.dirname(__FILE__) + "/../cli/setup"
2
-
3
- FlexmlsApi.configure do |config|
4
- config.api_key = ENV["API_KEY"]
5
- config.api_secret = ENV["API_SECRET"]
6
- config.api_user = ENV["API_USER"] if ENV["API_USER"]
7
- config.endpoint = ENV["API_ENDPOINT"] if ENV["API_ENDPOINT"]
8
- end
@@ -1,14 +0,0 @@
1
- require File.dirname(__FILE__) + "/../cli/setup"
2
-
3
- FlexmlsApi.configure do |config|
4
- config.oauth2_provider = FlexmlsApi::Authentication::OAuth2Impl::PasswordProvider.new(
5
- :authorization_uri=> ENV["AUTH_URI"],
6
- :access_uri => ENV["ACCESS_URI"],
7
- :username=> ENV["USERNAME"],
8
- :password=> ENV["PASSWORD"],
9
- :client_id=> ENV["CLIENT_ID"],
10
- :client_secret=> ENV["CLIENT_SECRET"]
11
- )
12
- config.authentication_mode = FlexmlsApi::Authentication::OAuth2
13
- config.endpoint = ENV["API_ENDPOINT"] if ENV["API_ENDPOINT"]
14
- end
@@ -1,47 +0,0 @@
1
- require "rubygems"
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"
6
-
7
- if ENV["FLEXMLS_API_CONSOLE"].nil?
8
- require 'flexmls_api'
9
- else
10
- puts "Enabling console mode for local gem"
11
- Bundler.require(:default, "development") if defined?(Bundler)
12
- path = File.expand_path(File.dirname(__FILE__) + "/../../../lib/")
13
- $LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
14
- require path + '/flexmls_api'
15
- end
16
-
17
- IRB.conf[:AUTO_INDENT]=true
18
- IRB.conf[:PROMPT][:FLEXMLS]= {
19
- :PROMPT_I => "flexmlsApi:%03n:%i> ",
20
- :PROMPT_S => "flexmlsApi:%03n:%i%l ",
21
- :PROMPT_C => "flexmlsApi:%03n:%i* ",
22
- :RETURN => "%s\n"
23
- }
24
-
25
- IRB.conf[:PROMPT_MODE] = :FLEXMLS
26
-
27
- path = File.expand_path(File.dirname(__FILE__) + "/../../../lib/")
28
- $LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
29
- require path + '/flexmls_api'
30
-
31
- module FlexmlsApi
32
- def self.logger
33
- if @logger.nil?
34
- @logger = Logger.new(STDOUT)
35
- @logger.level = ENV["DEBUG"].nil? ? Logger::WARN : Logger::DEBUG
36
- end
37
- @logger
38
- end
39
- end
40
-
41
- FlexmlsApi.logger.info("Client configured!")
42
-
43
- include FlexmlsApi::Models
44
-
45
- def c
46
- FlexmlsApi.client
47
- end
@@ -1,54 +0,0 @@
1
- module SparkApi
2
- module Configuration
3
-
4
- # valid configuration options
5
- VALID_OPTION_KEYS = [:api_key, :api_secret, :api_user, :endpoint, :user_agent, :version, :ssl, :oauth2_provider, :authentication_mode].freeze
6
- OAUTH2_KEYS = [:authorization_uri, :access_uri, :client_id, :client_secret,
7
- # Requirements for authorization_code grant type
8
- :redirect_uri,
9
- # Requirements for password grant type
10
- :username, :password
11
- ]
12
-
13
- require File.expand_path('../configuration/yaml', __FILE__)
14
-
15
- DEFAULT_API_KEY = nil
16
- DEFAULT_API_SECRET = nil
17
- DEFAULT_API_USER = nil
18
- DEFAULT_ENDPOINT = 'https://api.sparkapi.com'
19
- DEFAULT_VERSION = 'v1'
20
- DEFAULT_USER_AGENT = "Spark API Ruby Gem #{VERSION}"
21
- DEFAULT_SSL = true #false
22
- DEFAULT_OAUTH2 = nil
23
-
24
- X_SPARK_API_USER_AGENT = "X-SparkApi-User-Agent"
25
-
26
- attr_accessor *VALID_OPTION_KEYS
27
- def configure
28
- yield self
29
- end
30
-
31
- def self.extended(base)
32
- base.reset_configuration
33
- end
34
-
35
- def options
36
- VALID_OPTION_KEYS.inject({}) do |opt,key|
37
- opt.merge(key => send(key))
38
- end
39
- end
40
-
41
- def reset_configuration
42
- self.api_key = DEFAULT_API_KEY
43
- self.api_secret = DEFAULT_API_SECRET
44
- self.api_user = DEFAULT_API_USER
45
- self.authentication_mode = SparkApi::Authentication::ApiAuth
46
- self.endpoint = DEFAULT_ENDPOINT
47
- self.oauth2_provider = DEFAULT_OAUTH2
48
- self.user_agent = DEFAULT_USER_AGENT
49
- self.ssl = DEFAULT_SSL
50
- self.version = DEFAULT_VERSION
51
- self
52
- end
53
- end
54
- end
@@ -1,101 +0,0 @@
1
- require 'erb'
2
-
3
- module FlexmlsApi
4
- module Configuration
5
- class YamlConfig
6
- KEY_CONFIGURATIONS = VALID_OPTION_KEYS + [:oauth2] + OAUTH2_KEYS
7
- DEFAULT_OAUTH2_PROVIDER = "FlexmlsApi::Authentication::OAuth2Impl::PasswordProvider"
8
- attr_accessor *KEY_CONFIGURATIONS
9
- attr_reader :client_keys, :oauth2_keys, :provider
10
-
11
- def initialize(filename=nil)
12
- @oauth2 = false
13
- load_file(filename) unless filename.nil?()
14
- end
15
- def load_file(file)
16
- @file = file
17
- @name = File.basename(file, ".yml")
18
- config = YAML.load(ERB.new(File.read(file)).result)[api_env]
19
- config["oauth2"] == true ? load_oauth2(config) : load_api_auth(config)
20
- rescue => e
21
- FlexmlsApi.logger().error("Unable to load config file #{file}[#{api_env}]")
22
- raise e
23
- end
24
-
25
- def oauth2?
26
- return oauth2 == true
27
- end
28
-
29
- def name
30
- @name
31
- end
32
- def api_env
33
- current_env = "development"
34
- if env.include?("FLEXMLS_API_ENV")
35
- current_env = env["FLEXMLS_API_ENV"]
36
- elsif env.include?("RAILS_ENV")
37
- current_env = env["RAILS_ENV"]
38
- end
39
- return current_env
40
- end
41
-
42
- # Used to specify the root of where to look for flexmlsApi config files
43
- def self.config_path
44
- path_prefix + "config/flexmls_api"
45
- end
46
-
47
- def self.config_keys()
48
- files = Dir["#{config_path}/*.yml"]
49
- files.map {|f| File.basename(f,".yml") }
50
- end
51
-
52
- def self.exists?(name)
53
- File.exists? "#{config_path}/#{name}.yml"
54
- end
55
-
56
- def self.build(name)
57
- yaml = YamlConfig.new("#{config_path}/#{name}.yml")
58
- end
59
-
60
- protected
61
- def env
62
- ENV
63
- end
64
-
65
- private
66
- def load_api_auth(config={})
67
- @client_keys = {}
68
- @oauth2_keys = {}
69
- config.each do |key,val|
70
- sym = key.to_sym
71
- if VALID_OPTION_KEYS.include?(sym)
72
- self.send("#{sym}=", val)
73
- @client_keys[sym] = val
74
- end
75
- end
76
- end
77
- def load_oauth2(config={})
78
- @oauth2_provider = DEFAULT_OAUTH2_PROVIDER
79
- @client_keys = {:oauth2_provider => @oauth2_provider }
80
- @oauth2_keys = {}
81
- @oauth2 = true
82
- config.each do |key,val|
83
- sym = key.to_sym
84
- if VALID_OPTION_KEYS.include?(sym)
85
- self.send("#{sym}=", val)
86
- @client_keys[sym] = val
87
- elsif OAUTH2_KEYS.include? sym
88
- self.send("#{sym}=", val)
89
- @oauth2_keys[sym] = val
90
- end
91
- end
92
- end
93
- # In a rails app, default to the rails root, regardless of where that may be
94
- def self.path_prefix
95
- "#{Rails.root}/"
96
- rescue => e
97
- ""
98
- end
99
- end
100
- end
101
- end