Class: RandomApi::Service
- Inherits:
-
Object
- Object
- RandomApi::Service
- Includes:
- HTTParty
- Defined in:
- lib/random_api/service.rb
Instance Method Summary collapse
-
#initialize(api_key = nil) ⇒ Service
constructor
A new instance of Service.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #user(options = {}) ⇒ Object
- #users(count, options = {}) ⇒ Object
Constructor Details
#initialize(api_key = nil) ⇒ Service
Returns a new instance of Service.
10 11 12 |
# File 'lib/random_api/service.rb', line 10 def initialize(api_key = nil) @api_key = api_key end |
Instance Method Details
#inspect ⇒ Object
37 38 39 |
# File 'lib/random_api/service.rb', line 37 def inspect "#<RandomApi::Service " + (@api_key.nil? ? "anonymous" : "setup with key") + ">" end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/random_api/service.rb', line 33 def to_s "RandomAPI Service " + (@api_key.nil? ? "no api key given" : @api_key) end |
#user(options = {}) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/random_api/service.rb', line 14 def user( = {}) = .dup .delete(:results) # Single user request, no need = { query: .merge(()) } RandomApi::User.new(self.class.get("/", )["results"].first) end |
#users(count, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/random_api/service.rb', line 23 def users(count, = {}) = .dup [:results] = count = { query: .merge(()) } results = self.class.get("/", )["results"] results.map { |data| RandomApi::User.new(data) } end |