Class: Flespi

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

Constant Summary collapse

VERSION =
"1.0.2.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flespi_token, debug: false) ⇒ Flespi

Returns a new instance of Flespi.



12
13
14
15
# File 'lib/flespi.rb', line 12

def initialize(flespi_token, debug: false)
  self.flespi_token = flespi_token
  self.debug = debug
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



8
9
10
# File 'lib/flespi.rb', line 8

def debug
  @debug
end

#flespi_tokenObject

Returns the value of attribute flespi_token.



8
9
10
# File 'lib/flespi.rb', line 8

def flespi_token
  @flespi_token
end

Instance Method Details

#create(url, parameters) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/flespi.rb', line 31

def create(url, parameters)
  uri = URI.parse("https://flespi.io#{url}")

  if debug
    puts "================ FLESPI REQUEST ================"
    puts "Request: POST https://flespi.io#{url}"
    puts "================================================"
  end

  request = Net::HTTP::Post.new(uri)

  validate_response(make_request(request, uri, parameters))
end

#delete(url) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/flespi.rb', line 59

def delete(url)
  uri = URI.parse("https://flespi.io#{url}")

  if debug
    puts "================ FLESPI REQUEST ================"
    puts "Request: DELETE https://flespi.io#{url}"
    puts "================================================"
  end

  request = Net::HTTP::Delete.new(uri)

  validate_response(make_request(request, uri))
end

#get(url) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/flespi.rb', line 17

def get(url)
  uri = URI.parse("https://flespi.io#{url}")

  if debug
    puts "================ FLESPI REQUEST ================"
    puts "Request: GET https://flespi.io#{url}"
    puts "================================================"
  end

  request = Net::HTTP::Get.new(uri)

  validate_response(make_request(request, uri))
end

#update(url, parameters) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/flespi.rb', line 45

def update(url, parameters)
  uri = URI.parse("https://flespi.io#{url}")

  if debug
    puts "================ FLESPI REQUEST ================"
    puts "Request: PUT https://flespi.io#{url}"
    puts "================================================"
  end

  request = Net::HTTP::Put.new(uri)

  validate_response(make_request(request, uri, parameters))
end