Class: NetDNARWS::NetDNA
- Inherits:
-
Object
- Object
- NetDNARWS::NetDNA
- Defined in:
- lib/netdnarws.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
- #_connection_type ⇒ Object
- #_encode_params(values) ⇒ Object
- #_get_url(uri, attributes) ⇒ Object
- #_response_as_json(method, uri, options = {}, *attributes) ⇒ Object
- #delete(uri, data = {}, options = {}) ⇒ Object
- #get(uri, data = {}, options = {}) ⇒ Object
-
#initialize(company_alias, key, secret, server = 'rws.netdna.com', secure_connection = true, *options) ⇒ NetDNA
constructor
A new instance of NetDNA.
- #post(uri, data = {}, options = {}) ⇒ Object
- #put(uri, data = {}, options = {}) ⇒ Object
Constructor Details
#initialize(company_alias, key, secret, server = 'rws.netdna.com', secure_connection = true, *options) ⇒ NetDNA
Returns a new instance of NetDNA.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/netdnarws.rb', line 9 def initialize company_alias, key, secret, server='rws.netdna.com', secure_connection=true, * @company_alias = company_alias @server = server @secure_connection = secure_connection @request_signer = Signet::OAuth1::Client.new( :client_credential_key => key, :client_credential_secret => secret, :two_legged => true ) end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
8 9 10 |
# File 'lib/netdnarws.rb', line 8 def client @client end |
Instance Method Details
#_connection_type ⇒ Object
21 22 23 24 |
# File 'lib/netdnarws.rb', line 21 def _connection_type return "http" unless @secure_connection "https" end |
#_encode_params(values) ⇒ Object
26 27 28 29 30 |
# File 'lib/netdnarws.rb', line 26 def _encode_params values uri = Addressable::URI.new uri.query_values = values uri.query end |
#_get_url(uri, attributes) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/netdnarws.rb', line 32 def _get_url uri, attributes url = "#{_connection_type}://#{@server}/#{@company_alias}#{uri}" if not attributes.empty? url += "?#{_encode_params(attributes[0])}" end url end |
#_response_as_json(method, uri, options = {}, *attributes) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/netdnarws.rb', line 41 def _response_as_json method, uri, ={}, *attributes if .delete(:debug) puts "Making #{method.upcase} request to #{_get_url uri}" end = { :uri => _get_url(uri, attributes), :method => method } [:body] = _encode_params(attributes[0]) if [:body] request = @request_signer.generate_authenticated_request() begin = {} [:url] = _get_url(uri, attributes) [:headers] = request.headers if not [:body] response = CurbFu.send method, else response = CurbFu.send method, , request.body end return response if [:debug_request] response_json = JSON.load(response.body) return response_json if [:debug_json] if not (response.success? or response.redirect?) = response_json['error']['message'] raise Exception.new("#{response.status}: #{}") end rescue TypeError raise Exception.new( "#{response.status}: No information supplied by the server" ) end response_json end |
#delete(uri, data = {}, options = {}) ⇒ Object
99 100 101 102 |
# File 'lib/netdnarws.rb', line 99 def delete uri, data={}, ={} [:body] = false self._response_as_json 'delete', uri, , data end |
#get(uri, data = {}, options = {}) ⇒ Object
84 85 86 87 |
# File 'lib/netdnarws.rb', line 84 def get uri, data={}, ={} [:body] = false self._response_as_json 'get', uri, , data end |
#post(uri, data = {}, options = {}) ⇒ Object
89 90 91 92 |
# File 'lib/netdnarws.rb', line 89 def post uri, data={}, ={} [:body] = true self._response_as_json 'post', uri, , data end |
#put(uri, data = {}, options = {}) ⇒ Object
94 95 96 97 |
# File 'lib/netdnarws.rb', line 94 def put uri, data={}, ={} [:body] = true self._response_as_json 'put', uri, , data end |