Class: VkMusic::Request::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vk_music/request/base.rb

Overview

Base class for most of requests

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, data = {}, method = 'GET', headers = {}) ⇒ Base

Initialize new request

Parameters:

  • path (String)
  • data (Hash) (defaults to: {})
  • method (String) (defaults to: 'GET')
  • headers (Hash) (defaults to: {})


25
26
27
28
29
30
31
32
# File 'lib/vk_music/request/base.rb', line 25

def initialize(path, data = {}, method = 'GET', headers = {})
  @path = path
  @data = data
  @method = method.upcase
  @headers = headers

  @response = nil
end

Instance Attribute Details

#dataHash (readonly)

Returns:

  • (Hash)


12
13
14
# File 'lib/vk_music/request/base.rb', line 12

def data
  @data
end

#headersHash (readonly)

Returns:

  • (Hash)


16
17
18
# File 'lib/vk_music/request/base.rb', line 16

def headers
  @headers
end

#methodString (readonly)

Returns:

  • (String)


14
15
16
# File 'lib/vk_music/request/base.rb', line 14

def method
  @method
end

#pathString (readonly)

Returns:

  • (String)


10
11
12
# File 'lib/vk_music/request/base.rb', line 10

def path
  @path
end

#responseMechanize::File? (readonly)

Returns:

  • (Mechanize::File?)


18
19
20
# File 'lib/vk_music/request/base.rb', line 18

def response
  @response
end

Instance Method Details

#call(agent) ⇒ self

Parameters:

  • agent (Mechanize)

Returns:

  • (self)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vk_music/request/base.rb', line 36

def call(agent)
  before_call

  log
  @response = case method
  when 'GET' then get(agent)
  when 'POST' then post(agent)
  else raise(ArgumentError, "unsupported method #{method}")
  end

  after_call

  self
end