opener-webservice 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3c9e68800786848df8f2c1310b2063edbf58939
4
- data.tar.gz: e3b445eb8a225c5811663fc7dc5b0077c9e16077
3
+ metadata.gz: 2f0bbd6c49b5e68d01232c20dc174073ac66997b
4
+ data.tar.gz: 236c4398bfd4c39c509aca78844f6ffa293f8401
5
5
  SHA512:
6
- metadata.gz: 2f8b4978233d0f11a62828388c425e535be83c4dd8de2a78b06d1fec9b74c322a752dcf0ad5a65a3f365cf318837e0b7fa49d95eac38c10dcf1672c4658e946b
7
- data.tar.gz: 7980a3858ddfaf44d0c24c89097ee025352dbea0108b06085634f7df316d04e90c0fb5128705126919d8fb53e8cdff8fcb54b2abc93d7d12eb6b491ed2c951ee
6
+ metadata.gz: 86c9a155b512a6a682e8ecea0a646be4ed7f83fee8ca6805c98a2b71f134144474a4e8046267a433a323e5846fa7827934196245d1c397a9edb5651aeefd749b
7
+ data.tar.gz: 8d2725e610d1ecb603e64a3225a05d43db5de10e62cc3e2bf7cc4ee029579385b15ceb44e4d78c445d9fa586cd5cbbc9bcc24c09c4b750a2763380b6a7e20a9c
@@ -0,0 +1,103 @@
1
+ require 'sinatra/base'
2
+ require 'optparse'
3
+
4
+ module Opener
5
+ class Webservice < Sinatra::Base
6
+ class OptParser
7
+ attr_accessor :option_parser, :options
8
+
9
+ def initialize(&block)
10
+ @options = {}
11
+ @option_parser = construct_option_parser(options, &block)
12
+ end
13
+
14
+ def parse(args)
15
+ process(:parse, args)
16
+ end
17
+
18
+ def parse!(args)
19
+ process(:parse!, args)
20
+ end
21
+
22
+ def pre_parse!(args)
23
+ delete_double_dash = false
24
+ process(:parse!, args, delete_double_dash)
25
+ end
26
+
27
+ def pre_parse(args)
28
+ delete_double_dash = false
29
+ process(:parse, args, delete_double_dash)
30
+ end
31
+
32
+ def self.parse(args)
33
+ new.parse(args)
34
+ end
35
+
36
+ def self.parse!(args)
37
+ new.parse!(args)
38
+ end
39
+
40
+ def self.pre_parse!(args)
41
+ new.pre_parse!(args)
42
+ end
43
+
44
+ def self.pre_parse(args)
45
+ new.pre_parse(args)
46
+ end
47
+
48
+ private
49
+
50
+ def process(call, args, delete_double_dash=true)
51
+ args.delete("--") if delete_double_dash
52
+ option_parser.send(call, args)
53
+ return options
54
+ end
55
+
56
+ def construct_option_parser(options, &block)
57
+ script_name = File.basename($0, ".rb")
58
+
59
+ OptionParser.new do |opts|
60
+ if block_given?
61
+ opts.banner = "Usage: #{script_name} <start> [server_options] -- [authentication_options]"
62
+ else
63
+ opts.banner = "Usage: #{script_name} <start> [options]"
64
+ end
65
+
66
+ opts.separator ""
67
+
68
+ if block_given?
69
+ opts.separator "Component Specific options:"
70
+ opts.separator ""
71
+ yield opts, options
72
+ opts.separator ""
73
+ end
74
+
75
+ opts.separator "Authentication options:"
76
+
77
+ opts.on("--authentication", "--authentication AUTHENTICATION_ENDPOINT", "Endpoint for authenticating requests") do |v|
78
+ options[:authentication] = v
79
+ end
80
+
81
+ opts.on("--secret", "--secret SECRET_VARIABLE", "Accepted parameter variable for secret.") do |v|
82
+ options[:secret] = v
83
+ end
84
+
85
+ opts.on("--token", "--secret TOKEN_VARIABLE", "Accepted parameter variable for token.") do |v|
86
+ options[:token] = v
87
+ end
88
+
89
+ opts.separator ""
90
+
91
+ opts.separator "Common options:"
92
+
93
+ # No argument, shows at tail. This will print an options summary.
94
+ # Try it and see!
95
+ opts.on_tail("-h", "--help", "Show this message. Usage: #{script_name} -h") do
96
+ puts opts
97
+ exit
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -2,6 +2,6 @@ require 'sinatra/base'
2
2
 
3
3
  module Opener
4
4
  class Webservice < Sinatra::Base
5
- VERSION = "1.0.0"
5
+ VERSION = "1.0.1"
6
6
  end
7
7
  end
@@ -2,17 +2,33 @@ require "uuidtools"
2
2
  require "sinatra/base"
3
3
  require "json"
4
4
  require "opener/webservice/version"
5
+ require "opener/webservice/opt_parser"
5
6
 
6
7
  module Opener
7
8
  class Webservice < Sinatra::Base
8
9
  configure do
9
10
  enable :logging
11
+ if ARGV && pos = ARGV.index("--")
12
+ ws_options = ARGV[pos..-1]
13
+ else
14
+ ws_options = []
15
+ end
16
+ options = OptParser.parse!(ws_options)
17
+
18
+ options.each do |k,v|
19
+ Sinatra::Application.set k.to_sym, v
20
+ end
10
21
  end
11
22
 
12
23
  configure :development do
13
24
  set :raise_errors, true
14
25
  set :dump_errors, true
15
26
  end
27
+
28
+ before %r{^((?!.css|.jpg|.png|.js|.ico).)+$} do
29
+ extract_params
30
+ authenticate! if Sinatra::Application.respond_to?(:authentication)
31
+ end
16
32
 
17
33
  ##
18
34
  # Presents a simple form that can be used for getting the NER of a KAF
@@ -94,6 +110,7 @@ module Opener
94
110
  else
95
111
  @accepted_params = array
96
112
  end
113
+ @accepted_params.concat([secret_symbol, token_symbol]) if Sinatra::Application.respond_to?(:authentication)
97
114
  end
98
115
 
99
116
  ##
@@ -221,14 +238,16 @@ module Opener
221
238
  # Airbrake during the hackathon. For whatever reason somebody is posting
222
239
  # internal server errors from *somewhere*. Validation? What's that?
223
240
  return if text =~ /^internal server error/i
224
-
241
+
225
242
  output = {
226
243
  :input => text,
227
244
  :request_id => request_id,
228
245
  :'callbacks[]' => callbacks,
229
246
  :error_callback => error_callback
230
247
  }
231
-
248
+
249
+ extract_params
250
+
232
251
  http_client.post_async(
233
252
  url,
234
253
  :body => filtered_params.merge(output)
@@ -270,5 +289,38 @@ module Opener
270
289
  def http_client
271
290
  return self.class.http_client
272
291
  end
292
+
293
+ def authenticate!
294
+ credentials = {
295
+ secret_symbol => params[secret_symbol.to_s],
296
+ token_symbol => params[token_symbol.to_s]
297
+ }
298
+ response = http_client.get(Sinatra::Application.authentication, credentials)
299
+ halt response.body unless response.ok?
300
+ end
301
+
302
+ def extract_params
303
+ if request.referrer
304
+ uri = URI.parse(request.referrer)
305
+ extracted = Rack::Utils.parse_nested_query(uri.query)
306
+ params.merge!(extracted)
307
+ end
308
+ end
309
+
310
+ def self.secret_symbol
311
+ Sinatra::Application.respond_to?(:secret)? Sinatra::Application.secret.to_sym : :secret
312
+ end
313
+
314
+ def self.token_symbol
315
+ Sinatra::Application.respond_to?(:token)? Sinatra::Application.token.to_sym : :token
316
+ end
317
+
318
+ def secret_symbol
319
+ return self.class.secret_symbol
320
+ end
321
+
322
+ def token_symbol
323
+ return self.class.token_symbol
324
+ end
273
325
  end
274
326
  end
metadata CHANGED
@@ -1,131 +1,131 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-webservice
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - development@olery.com
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2014-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
- requirement: !ruby/object:Gem::Requirement
15
+ version_requirements: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
20
+ requirement: !ruby/object:Gem::Requirement
23
21
  requirements:
24
- - - "~>"
22
+ - - ~>
25
23
  - !ruby/object:Gem::Version
26
24
  version: '1.3'
25
+ prerelease: false
26
+ type: :development
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
29
34
  requirement: !ruby/object:Gem::Requirement
30
35
  requirements:
31
- - - ">="
36
+ - - '>='
32
37
  - !ruby/object:Gem::Version
33
38
  version: '0'
34
- type: :development
35
39
  prerelease: false
40
+ type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
36
43
  version_requirements: !ruby/object:Gem::Requirement
37
44
  requirements:
38
- - - ">="
45
+ - - '>='
39
46
  - !ruby/object:Gem::Version
40
47
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: pry
43
48
  requirement: !ruby/object:Gem::Requirement
44
49
  requirements:
45
- - - ">="
50
+ - - '>='
46
51
  - !ruby/object:Gem::Version
47
52
  version: '0'
48
- type: :development
49
53
  prerelease: false
54
+ type: :development
55
+ - !ruby/object:Gem::Dependency
56
+ name: sinatra
50
57
  version_requirements: !ruby/object:Gem::Requirement
51
58
  requirements:
52
- - - ">="
59
+ - - ~>
53
60
  - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: sinatra
61
+ version: 1.4.3
57
62
  requirement: !ruby/object:Gem::Requirement
58
63
  requirements:
59
- - - "~>"
64
+ - - ~>
60
65
  - !ruby/object:Gem::Version
61
66
  version: 1.4.3
62
- type: :runtime
63
67
  prerelease: false
68
+ type: :runtime
69
+ - !ruby/object:Gem::Dependency
70
+ name: uuidtools
64
71
  version_requirements: !ruby/object:Gem::Requirement
65
72
  requirements:
66
- - - "~>"
73
+ - - '>='
67
74
  - !ruby/object:Gem::Version
68
- version: 1.4.3
69
- - !ruby/object:Gem::Dependency
70
- name: uuidtools
75
+ version: '0'
71
76
  requirement: !ruby/object:Gem::Requirement
72
77
  requirements:
73
- - - ">="
78
+ - - '>='
74
79
  - !ruby/object:Gem::Version
75
80
  version: '0'
76
- type: :runtime
77
81
  prerelease: false
82
+ type: :runtime
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
78
85
  version_requirements: !ruby/object:Gem::Requirement
79
86
  requirements:
80
- - - ">="
87
+ - - '>='
81
88
  - !ruby/object:Gem::Version
82
89
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: json
85
90
  requirement: !ruby/object:Gem::Requirement
86
91
  requirements:
87
- - - ">="
92
+ - - '>='
88
93
  - !ruby/object:Gem::Version
89
94
  version: '0'
90
- type: :runtime
91
95
  prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
96
+ type: :runtime
97
97
  description: Basic webservice hooks for the opener toolchain
98
- email:
98
+ email:
99
99
  executables: []
100
100
  extensions: []
101
101
  extra_rdoc_files: []
102
102
  files:
103
103
  - README.md
104
104
  - lib/opener/webservice.rb
105
+ - lib/opener/webservice/opt_parser.rb
105
106
  - lib/opener/webservice/version.rb
106
107
  - opener-webservice.gemspec
107
- homepage:
108
+ homepage:
108
109
  licenses: []
109
110
  metadata: {}
110
- post_install_message:
111
+ post_install_message:
111
112
  rdoc_options: []
112
113
  require_paths:
113
114
  - lib
114
115
  required_ruby_version: !ruby/object:Gem::Requirement
115
116
  requirements:
116
- - - ">="
117
+ - - '>='
117
118
  - !ruby/object:Gem::Version
118
119
  version: '0'
119
120
  required_rubygems_version: !ruby/object:Gem::Requirement
120
121
  requirements:
121
- - - ">="
122
+ - - '>='
122
123
  - !ruby/object:Gem::Version
123
124
  version: '0'
124
125
  requirements: []
125
- rubyforge_project:
126
+ rubyforge_project:
126
127
  rubygems_version: 2.2.2
127
- signing_key:
128
+ signing_key:
128
129
  specification_version: 4
129
130
  summary: Basic webservice hooks for the opener toolchain
130
131
  test_files: []
131
- has_rdoc: