Class: EngagingNetworksRest::Client
- Inherits:
-
Object
- Object
- EngagingNetworksRest::Client
- Includes:
- Pages
- Defined in:
- lib/engaging_networks_rest/client.rb,
lib/engaging_networks_rest/client/pages.rb
Defined Under Namespace
Modules: Pages
Constant Summary collapse
- ENS_DOMAIN =
'www.e-activist.com'.freeze
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#ens_auth_key ⇒ Object
readonly
Returns the value of attribute ens_auth_key.
Instance Method Summary collapse
- #authenticate! ⇒ Object
- #authenticated? ⇒ Boolean
- #get(path:, params: {}) ⇒ Object
-
#initialize(api_key:) ⇒ Client
constructor
A new instance of Client.
- #post(path:, body: {}) ⇒ Object
Methods included from Pages
#page, #pages, #process_page_request
Constructor Details
#initialize(api_key:) ⇒ Client
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/engaging_networks_rest/client.rb', line 12 def initialize(api_key:) @api_key = api_key @connection = Faraday.new(url: "https://#{ENS_DOMAIN}") do |conn| conn.request :json conn.response :json, :content_type => /\bjson$/ conn.use Faraday::Response::Logger if ENV['DEBUG'] conn.use EngagingNetworksRest::Response::RaiseError conn.adapter :net_http end end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/engaging_networks_rest/client.rb', line 8 def api_key @api_key end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
8 9 10 |
# File 'lib/engaging_networks_rest/client.rb', line 8 def connection @connection end |
#ens_auth_key ⇒ Object (readonly)
Returns the value of attribute ens_auth_key.
8 9 10 |
# File 'lib/engaging_networks_rest/client.rb', line 8 def ens_auth_key @ens_auth_key end |
Instance Method Details
#authenticate! ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/engaging_networks_rest/client.rb', line 26 def authenticate! response = connection.post do |req| req.headers['Content-Type'] = 'application/json' req.url '/ens/service/authenticate' req.body = api_key end @ens_auth_key = response.body['ens-auth-token'] end |
#authenticated? ⇒ Boolean
36 37 38 |
# File 'lib/engaging_networks_rest/client.rb', line 36 def authenticated? !ens_auth_key.nil? end |
#get(path:, params: {}) ⇒ Object
40 41 42 |
# File 'lib/engaging_networks_rest/client.rb', line 40 def get(path:, params: {}) request(method: :get, path: path, params: params) end |
#post(path:, body: {}) ⇒ Object
44 45 46 |
# File 'lib/engaging_networks_rest/client.rb', line 44 def post(path:, body: {}) request(method: :post, path: path, body: body) end |