Class: Yamori::Rest::Http

Inherits:
Object
  • Object
show all
Defined in:
lib/yamori/rest/http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance_url, access_token) ⇒ Http

Returns a new instance of Http.



10
11
12
13
# File 'lib/yamori/rest/http.rb', line 10

def initialize(instance_url, access_token)
  @instance_url = instance_url
  @access_token = access_token
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



8
9
10
# File 'lib/yamori/rest/http.rb', line 8

def access_token
  @access_token
end

#instance_urlObject (readonly)

Returns the value of attribute instance_url.



8
9
10
# File 'lib/yamori/rest/http.rb', line 8

def instance_url
  @instance_url
end

Instance Method Details

#delete(path) ⇒ Object



41
42
43
44
# File 'lib/yamori/rest/http.rb', line 41

def delete(path)
  response = post_request(path + '?_HttpMethod=DELETE', '')
  response.code
end

#get(path) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/yamori/rest/http.rb', line 15

def get(path)
  url = URI.parse(instance_url + path)
  res = Net::HTTP.get(url, headers)

  if res =~/errorCode/
    err = JSON.parse(res).first
    if err['errorCode'] == 'NOT_FOUND'
      raise RecordNotFoundError.new
    else
      raise RequestError.new(err['errorCode'], err['message'])
    end
  end

  res
end

#patch(path, data) ⇒ Object



36
37
38
39
# File 'lib/yamori/rest/http.rb', line 36

def patch(path, data)
  response = post_request(path + '?_HttpMethod=PATCH', data)
  response.code
end

#post(path, data) ⇒ Object



31
32
33
34
# File 'lib/yamori/rest/http.rb', line 31

def post(path, data)
  response = post_request(path, data)
  response.body
end