Class: Telegrammer::ApiResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/telegrammer/api_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, fail_silently = false) ⇒ ApiResponse

Returns a new instance of ApiResponse.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/telegrammer/api_response.rb', line 7

def initialize(response,fail_silently = false)
  if response.status < 500
    @body = response.body

    data = MultiJson.load(@body)
    @success = data['ok']

    if @success
      @result = data['result']
    else
      if !fail_silently
        fail Telegrammer::Errors::BadRequestError.new(data['error_code'], data['description'])
      end
    end
  else
    if !fail_silently
      fail Telegrammer::Errors::ServiceUnavailableError.new(response.status)
    end
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/telegrammer/api_response.rb', line 3

def body
  @body
end

#resultObject (readonly)

Returns the value of attribute result.



4
5
6
# File 'lib/telegrammer/api_response.rb', line 4

def result
  @result
end

#successObject (readonly) Also known as: success?

Returns the value of attribute success.



5
6
7
# File 'lib/telegrammer/api_response.rb', line 5

def success
  @success
end