Module: Viner::Request

Included in:
Client
Defined in:
lib/viner/request.rb

Instance Method Summary collapse

Instance Method Details

#call(http_verb, url, opts = {}) ⇒ Object



6
7
8
9
# File 'lib/viner/request.rb', line 6

def call(http_verb, url, opts={})
  result = connection(http_verb, url, opts)
  Hashie::Mash.new(result.body)
end

#connection(http_verb, url, opts = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/viner/request.rb', line 11

def connection(http_verb, url, opts={})
  opts.has_key?(:headers) ? nil : opts[:headers] = {}
  opts.has_key?(:parameters) ? nil : opts[:parameters] = nil
  Unirest.default_header('User-Agent','com.vine.iphone/1.0.3 (unknown, iPhone OS 6.0.1, iPhone, Scale/2.000000)')
  Unirest.default_header('Accept-Language','en, sv, fr, de, ja, nl, it, es, pt, pt-PT, da, fi, nb, ko, zh-Hans, zh-Hant, ru, pl, tr, uk, ar, hr, cs, el, he, ro, sk, th, id, ms, en-GB, ca, hu, vi, en-us;q=0.8')
  Unirest.default_header('vine-session-id', @key) if @key

  case http_verb
  when :get
    Unirest.get ENDPOINT+url, headers: opts[:headers], parameters: opts[:parameters]
  when :post
    Unirest.post ENDPOINT+url, headers: opts[:headers], parameters: opts[:parameters]
  when :delete
    Unirest.delete ENDPOINT+url, headers: opts[:headers], parameters: opts[:parameters]
  when :put
    Unirest.put ENDPOINT+url, headers: opts[:headers], parameters: opts[:parameters]
  when :patch
    Unirest.patch ENDPOINT+url, headers: opts[:headers], parameters: opts[:parameters]
  end
end