Class: Abrupt::Service::Base
Overview
base class
Direct Known Subclasses
AbsoluteUrl, Complexity, Input, Link, Picture, Readability, Subject
Constant Summary collapse
- SERVICE_URI =
TODO: outsource service uri to module Service
'http://wba.cs.hs-rm.de/AbRUPt/service/complexity/public/index.php/api/v1/complexity'
Instance Attribute Summary collapse
-
#abbr ⇒ Object
Returns the value of attribute abbr.
-
#options ⇒ Object
Returns the value of attribute options.
-
#response ⇒ Object
Returns the value of attribute response.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#execute ⇒ Object
TODO: naming of interface execute.
-
#initialize(html, options = {}) ⇒ Base
constructor
A new instance of Base.
- #service_uri ⇒ Object
Constructor Details
#initialize(html, options = {}) ⇒ Base
Returns a new instance of Base.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/abrupt/service/base.rb', line 15 def initialize(html, = {}) @html = html = query_params = if .count > 0 = .map { |k, v| "#{k}=#{v}" } '?' + .reduce { |a, e| "#{a}&#{e}" } else '' end @url = service_uri + query_params @abbr = self.class.name[0].downcase = [] end |
Instance Attribute Details
#abbr ⇒ Object
Returns the value of attribute abbr.
7 8 9 |
# File 'lib/abrupt/service/base.rb', line 7 def abbr @abbr end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/abrupt/service/base.rb', line 7 def end |
#response ⇒ Object
Returns the value of attribute response.
7 8 9 |
# File 'lib/abrupt/service/base.rb', line 7 def response @response end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/abrupt/service/base.rb', line 7 def url @url end |
Class Method Details
.available_options ⇒ Object
29 30 31 |
# File 'lib/abrupt/service/base.rb', line 29 def self. [] end |
.keyname ⇒ Object
33 34 35 |
# File 'lib/abrupt/service/base.rb', line 33 def self.keyname name.split('::').last.downcase end |
.transform_hash(hsh) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/abrupt/service/base.rb', line 56 def self.transform_hash(hsh) uri = Addressable::URI.parse(hsh.keys.first).normalize result = { website: { domain: "#{uri.scheme}://#{uri.host}", url: [] } } hsh.each_with_index do |(key, value), _index| page = { name: key, state: value } result[:website][:url] << page end result.deep_symbolize_keys end |
Instance Method Details
#execute ⇒ Object
TODO: naming of interface execute
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/abrupt/service/base.rb', line 38 def execute = { method: :post, timeout: 6000, open_timeout: 6000, accept: :schema } .merge!(url: @url, payload: @html) begin res = RestClient::Request.execute().to_str @response = JSON.parse(res) rescue => e puts "some problems with #{@url}" puts e nil end end |
#service_uri ⇒ Object
11 12 13 |
# File 'lib/abrupt/service/base.rb', line 11 def service_uri SERVICE_URI end |