Class: Bitcodin::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcodin/network/http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(apiKey, headers) ⇒ HTTP

Returns a new instance of HTTP.


16
17
18
19
# File 'lib/bitcodin/network/http.rb', line 16

def initialize(apiKey, headers)
  @apiKey  = apiKey
  @headers = headers
end

Instance Attribute Details

#apiKeyObject

Returns the value of attribute apiKey


14
15
16
# File 'lib/bitcodin/network/http.rb', line 14

def apiKey
  @apiKey
end

#headersObject

Returns the value of attribute headers


14
15
16
# File 'lib/bitcodin/network/http.rb', line 14

def headers
  @headers
end

Instance Method Details

#callResourceDelete(url) ⇒ Object


74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/bitcodin/network/http.rb', line 74

def callResourceDelete(url)
  # puts 'Delete'
  # puts url
  begin
    response = RestClient.delete url, @headers
    return response
  rescue Exception => e
    puts e.message
    puts e.backtrace.inspect
    return nil
  end
end

#callResourceGet(url) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bitcodin/network/http.rb', line 34

def callResourceGet(url)
  # puts 'Get'
  # puts url
  begin
    response = RestClient.get url, @headers
    return response
  rescue Exception => e
    puts e.message
    puts e.backtrace.inspect
    return nil
  end
end

#callResourcePatch(url) ⇒ Object


47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/bitcodin/network/http.rb', line 47

def callResourcePatch(url)
  # puts 'Patch'
  # puts url
  begin
    response = RestClient.patch url, @headers
    return response
  rescue Exception => e
    puts e.message
    puts e.backtrace.inspect
    return nil
  end
end

#callResourcePost(url, value) ⇒ Object


60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/bitcodin/network/http.rb', line 60

def callResourcePost(url, value)
  # puts 'Post'
  # puts url
  # puts value
  begin
    response = RestClient.post url, value, @headers
    return response
  rescue Exception => e
    puts e.message
    puts e.backtrace.inspect
    return nil
  end
end

#sendRequest(method, url, values = nil) ⇒ Object


21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bitcodin/network/http.rb', line 21

def sendRequest(method, url, values = nil)
  case method
    when 'get'
      callResourceGet(url)
    when 'patch'
      callResourcePatch(url)
    when 'post'
      callResourcePost(url, values)
    when 'delete'
      callResourceDelete(url)
  end
end