Class: Quandora::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/quandora/request.rb

Direct Known Subclasses

Activity, Answer, Badges, Bases, EndPoints, Question, Users

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conn, api, params) ⇒ Request

Returns a new instance of Request.



4
5
6
7
8
# File 'lib/quandora/request.rb', line 4

def initialize(conn, api, params)
  @conn = conn
  @api = api
  @params = params
end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



2
3
4
# File 'lib/quandora/request.rb', line 2

def api
  @api
end

#paramsObject

Returns the value of attribute params.



2
3
4
# File 'lib/quandora/request.rb', line 2

def params
  @params
end

Instance Method Details

#index(args = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/quandora/request.rb', line 10

def index(args = {})
  args = args.stringify_keys

  @params.merge!("o": args["o"]) unless args.fetch('o', nil).nil?
  @params.merge!("l": args["l"]) unless args.fetch('l', nil).nil?

  resp = @conn.get(@api.to_s) do |req|
    req.params = @params
    req.headers['Content-Type'] = 'application/json'
  end
end

#show(id, args = {}) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/quandora/request.rb', line 22

def show(id, args = {})
  args = args.stringify_keys

  resp = @conn.get("#{@api}/#{id}") do |req|
    req.params = @params
    req.headers['Content-Type'] = 'application/json'
  end
end