spark_api 1.4.14 → 1.4.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Njk4NDliNTI2YjZjZjE1MjViYTk4NzYwYzcxNDJmYThlNzc0NzczMg==
4
+ YjZlZjMzZmMxM2VhODU0OTVlMGIyZDhhZGQ2ZWE5ZDUzNGU4MDJhMA==
5
5
  data.tar.gz: !binary |-
6
- NzA5YTA4MTkwYTBiMmMxNmQ2MTExMWYzODllZjgyZGY1Mzg4ODNjZA==
6
+ N2Y2MGMzODc0YTI5NTJlODE5ZTUwMjc0MzA1NmZhZTE3ZTRmZGMzYw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Y2JmYTY0YmRlYzAxNWNlNDllNTRmODQ2ZDNlZTkxMTIwYWM2ODhkZjc4MmJk
10
- MTI2MzIyZGZlN2QwMTUwZTUzOTUxNDIwMTliZjRlYzc5ZDk5YmZlNWI0ZDg2
11
- OTMyZmUyZDc3NDM4ZDlkYzI2Yjc1Y2IxNDA5ZmUwNjdiZjU0ZmQ=
9
+ ZDczNmFhZjM3ODIxZmI4Yzc0ZGEyZDczMTdmMmMyZTljNzYwNmJlYWIyNDhh
10
+ YTVlNzk4ZGYxNzNkMDRlYzI3OGMwY2ZhZDg3ODE2ZTBjNTY0NmExYjA0YjVj
11
+ MTJiNTZjNDg2NjhmMDM0MzE0ZjQ3ZDY5MGE1Y2U5Yjc2YWI0Zjc=
12
12
  data.tar.gz: !binary |-
13
- ZjQ2YTQyMjAwMTJiMzQwZTQ0MWM4MjFjNDQ0MjY3NTdkMDRjN2Y0YTY5Yzcw
14
- NzRiYTUwMWY5YTcxOGRlODZjOTc4NDVlMzA3ZWVmZGRmYWU3MzI4YjNjYjky
15
- YTJlZGI3MDQwZjRlNTJlNzQ3NzExNzY5ZWM2N2EzZjQ1NDg4M2M=
13
+ NzEwMzM3YTIwODY1YjQ1MGZjY2Y1OTYyZmQ2MWNkOTI4Njg1MDk4YWI2NDQz
14
+ YjVjNmUzNjVlNTg1Y2M1MDZkMDk0YTRmNWY3MmU5ZjAwZGM3NDc5MDZjODlj
15
+ ZjNiNDUxN2ViYTYwNTA2NjhmZDI3ZjAwODFkMzBmODZkZGQ4OGY=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.14
1
+ 1.4.15
@@ -13,6 +13,7 @@ require 'spark_api/request'
13
13
  require 'spark_api/connection'
14
14
  require 'spark_api/client'
15
15
  require 'spark_api/faraday_middleware'
16
+ require 'spark_api/reso_faraday_middleware'
16
17
  require 'spark_api/primary_array'
17
18
  require 'spark_api/options_hash'
18
19
  require 'spark_api/models'
@@ -19,7 +19,7 @@ module SparkApi
19
19
  sig = sign("#{@client.api_secret}ApiKey#{@client.api_key}")
20
20
  SparkApi.logger.debug { "Authenticating to #{@client.endpoint}" }
21
21
  start_time = Time.now
22
- request_path = "/#{@client.version}/session?ApiKey=#{@client.api_key}&ApiSig=#{sig}"
22
+ request_path = "#{SparkApi::Configuration::DEFAULT_SESSION_PATH}?ApiKey=#{@client.api_key}&ApiSig=#{sig}"
23
23
  resp = @client.connection(true).post request_path, ""
24
24
  request_time = Time.now - start_time
25
25
  SparkApi.logger.info { "[#{(request_time * 1000).to_i}ms] Api: POST #{request_path}" }
@@ -31,6 +31,7 @@ module SparkApi
31
31
  :api_user => "API_USER",
32
32
  # OTHER
33
33
  :debug=> "DEBUG",
34
+ :middleware => "SPARK_MIDDLEWARE",
34
35
  :console => "SPARK_API_CONSOLE" # not a public option, meant to distinguish bin/spark_api and script/console
35
36
  }
36
37
 
@@ -69,7 +70,8 @@ module SparkApi
69
70
  :api_secret => ENV[OPTIONS_ENV[:api_secret]],
70
71
  :api_user => ENV[OPTIONS_ENV[:api_user]],
71
72
  :ssl_verify => ENV.fetch(OPTIONS_ENV[:ssl_verify], true),
72
- :console => ENV[OPTIONS_ENV[:console]]
73
+ :console => ENV[OPTIONS_ENV[:console]],
74
+ :middleware => ENV[OPTIONS_ENV[:middleware]]
73
75
  }
74
76
  cli_options = {}
75
77
  file_options = {}
@@ -128,7 +130,10 @@ module SparkApi
128
130
  opts.on("--api_user API_USER",
129
131
  "ID of the Spark user to run the client as.",
130
132
  "Default: ENV['#{OPTIONS_ENV[:api_user]}']") { |arg| cli_options[:api_user] = arg }
131
-
133
+ opts.on("--middleware SPARK_MIDDLEWARE",
134
+ "spark_api for accessing spark, reso_api for accessing reso adapter",
135
+ "Default: spark_api") { |arg| cli_options[:middleware] = arg }
136
+
132
137
  # General
133
138
  opts.on("-f", "--file FILE",
134
139
  "Load configuration for yaml file.") { |arg| file_options = parse_file_options(arg) }
@@ -6,4 +6,5 @@ SparkApi.configure do |config|
6
6
  config.api_user = ENV["API_USER"] if ENV["API_USER"]
7
7
  config.endpoint = ENV["API_ENDPOINT"] if ENV["API_ENDPOINT"]
8
8
  config.ssl_verify = ENV["SSL_VERIFY"].downcase != 'false' if ENV["SSL_VERIFY"]
9
+ config.middleware = ENV["SPARK_MIDDLEWARE"] if ENV["SPARK_MIDDLEWARE"]
9
10
  end
@@ -19,6 +19,7 @@ SparkApi.configure do |config|
19
19
  config.authentication_mode = SparkApi::Authentication::OAuth2
20
20
  config.endpoint = ENV["API_ENDPOINT"] if ENV["API_ENDPOINT"]
21
21
  config.ssl_verify = ENV["SSL_VERIFY"].downcase != 'false' if ENV["SSL_VERIFY"]
22
+ config.middleware = ENV["SPARK_MIDDLEWARE"] if ENV["SPARK_MIDDLEWARE"]
22
23
  end
23
24
 
24
25
  # Enables saving and loading serialized oauth2 sessions for the system user.
@@ -11,7 +11,7 @@ module SparkApi
11
11
  # valid configuration options
12
12
  VALID_OPTION_KEYS = [:api_key, :api_secret, :api_user, :endpoint,
13
13
  :user_agent, :version, :ssl, :ssl_verify, :oauth2_provider, :authentication_mode,
14
- :auth_endpoint, :callback, :compress, :timeout].freeze
14
+ :auth_endpoint, :callback, :compress, :timeout, :middleware].freeze
15
15
  OAUTH2_KEYS = [:authorization_uri, :access_uri, :client_id, :client_secret,
16
16
  # Requirements for authorization_code grant type
17
17
  :redirect_uri,
@@ -36,12 +36,14 @@ module SparkApi
36
36
  DEFAULT_AUTHORIZATION_URI = 'https://sparkplatform.com/oauth2'
37
37
  DEFAULT_VERSION = 'v1'
38
38
  DEFAULT_ACCESS_URI = "#{DEFAULT_ENDPOINT}/#{DEFAULT_VERSION}/oauth2/grant"
39
+ DEFAULT_SESSION_PATH = "/#{DEFAULT_VERSION}/session"
39
40
  DEFAULT_USER_AGENT = "Spark API Ruby Gem #{VERSION}"
40
41
  DEFAULT_SSL = true
41
42
  DEFAULT_SSL_VERIFY = true
42
43
  DEFAULT_OAUTH2 = nil
43
44
  DEFAULT_COMPRESS = false
44
45
  DEFAULT_TIMEOUT = 5 # seconds
46
+ DEFAULT_MIDDLEWARE = 'spark_api'
45
47
 
46
48
  X_SPARK_API_USER_AGENT = "X-SparkApi-User-Agent"
47
49
 
@@ -75,6 +77,7 @@ module SparkApi
75
77
  self.version = DEFAULT_VERSION
76
78
  self.compress = DEFAULT_COMPRESS
77
79
  self.timeout = DEFAULT_TIMEOUT
80
+ self.middleware = DEFAULT_MIDDLEWARE
78
81
  self
79
82
  end
80
83
  end
@@ -23,7 +23,7 @@ module SparkApi
23
23
  end
24
24
 
25
25
  conn = Faraday.new(opts) do |conn|
26
- conn.response :spark_api
26
+ conn.response self.middleware.to_sym
27
27
  conn.options[:timeout] = self.timeout
28
28
  conn.adapter Faraday.default_adapter
29
29
  end
@@ -33,6 +33,14 @@ module SparkApi
33
33
 
34
34
  # HTTP request headers for client requests
35
35
  def headers
36
+ if self.middleware.to_sym == :reso_api
37
+ reso_headers
38
+ else
39
+ spark_headers
40
+ end
41
+ end
42
+
43
+ def spark_headers
36
44
  {
37
45
  :accept => 'application/json',
38
46
  :content_type => 'application/json',
@@ -40,6 +48,14 @@ module SparkApi
40
48
  Configuration::X_SPARK_API_USER_AGENT => user_agent
41
49
  }
42
50
  end
51
+
52
+ def reso_headers
53
+ {
54
+ :accept => 'application/json, application/xml',
55
+ :user_agent => Configuration::DEFAULT_USER_AGENT,
56
+ Configuration::X_SPARK_API_USER_AGENT => user_agent
57
+ }
58
+ end
43
59
 
44
60
  end
45
61
  end
@@ -86,6 +86,8 @@ module SparkApi
86
86
  end
87
87
 
88
88
  end
89
+
89
90
  Faraday::Response.register_middleware :spark_api => FaradayMiddleware
90
91
 
91
92
  end
93
+
@@ -65,7 +65,11 @@ module SparkApi
65
65
  begin
66
66
  request_opts = {}
67
67
  request_opts.merge!(options)
68
- request_path = "/#{version}#{path}"
68
+ request_path = if middleware && middleware.to_sym == :reso_api
69
+ "/Reso/OData#{path}"
70
+ else
71
+ "/#{version}#{path}"
72
+ end
69
73
  start_time = Time.now
70
74
  if [:get, :delete, :head].include?(method.to_sym)
71
75
  response = authenticator.request(method, request_path, nil, request_opts)
@@ -0,0 +1,30 @@
1
+
2
+ module SparkApi
3
+
4
+ class ResoFaradayMiddleware < FaradayMiddleware
5
+
6
+ def on_complete(env)
7
+
8
+ body = decompress_body(env)
9
+
10
+ begin
11
+ body = MultiJson.decode(body)
12
+
13
+ if body["D"]
14
+ super(env)
15
+ return
16
+ end
17
+
18
+ env[:body] = body
19
+ rescue MultiJson::ParseError => e
20
+ # We will allow the client to choose their XML parser, but should do
21
+ # some minor format verification
22
+ raise e if body.strip[/\A<\?xml/].nil?
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+
29
+ Faraday::Response.register_middleware :reso_api => ResoFaradayMiddleware
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spark_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.14
4
+ version: 1.4.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Hornseth
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-06-19 00:00:00.000000000 Z
12
+ date: 2017-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -369,6 +369,7 @@ files:
369
369
  - lib/spark_api/paginate.rb
370
370
  - lib/spark_api/primary_array.rb
371
371
  - lib/spark_api/request.rb
372
+ - lib/spark_api/reso_faraday_middleware.rb
372
373
  - lib/spark_api/response.rb
373
374
  - lib/spark_api/version.rb
374
375
  - script/bootstrap