Class: LayersService::ApiClient
- Inherits:
-
Object
- Object
- LayersService::ApiClient
- Defined in:
- lib/layers_service/api_client.rb
Overview
Implement all Layers API calls
Instance Method Summary collapse
- #get_user_by_id(user_id) ⇒ Object
-
#initialize(community_id) ⇒ ApiClient
constructor
A new instance of ApiClient.
- #inspect ⇒ Object
Constructor Details
#initialize(community_id) ⇒ ApiClient
Returns a new instance of ApiClient.
8 9 10 11 12 13 14 15 16 |
# File 'lib/layers_service/api_client.rb', line 8 def initialize(community_id) # Initialize base configuration to retrieve information from Layers's API @layers_routes = LayersRoutes.new(base_url: LayersService.configuration.base_url) @layers_app_token = LayersService.configuration.layers_token @community_id = community_id return unless @layers_app_token.nil? raise "It is mandatory to define the environment variables: 'LAYERS_TOKEN'" end |
Instance Method Details
#get_user_by_id(user_id) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/layers_service/api_client.rb', line 18 def get_user_by_id(user_id) url = URI("#{@layers_routes.users_route}/#{user_id}") https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Get.new(url) request["community-id"] = @community_id request["Content-Type"] = "application/json" request["Authorization"] = "Bearer #{@layers_app_token}" LayersResponse.new(https.request(request)) end |
#inspect ⇒ Object
29 30 31 |
# File 'lib/layers_service/api_client.rb', line 29 def inspect "#<LayersService::ApiClient>" end |