Class: Hockey::Networking

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

Overview

Networking Core Lib

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, debug: false) ⇒ Networking

Returns a new instance of Networking

Raises:

  • (ArgumentError)

22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hockeyhelper/networking.rb', line 22

def initialize(token, debug: false)
  raise(ArgumentError, 'token must be an instance of String') unless token.kind_of?(String)

  @client = Faraday.new(:url => 'https://rink.hockeyapp.net')
  @token = token
  @l = if debug
         Logger.new(STDOUT)
       else
         NullLogger.new
       end
end

Instance Attribute Details

#lObject (readonly)

Returns the value of attribute l


20
21
22
# File 'lib/hockeyhelper/networking.rb', line 20

def l
  @l
end

Instance Method Details

#delete(path) ⇒ Object


76
77
78
79
80
81
82
83
84
85
# File 'lib/hockeyhelper/networking.rb', line 76

def delete(path)
  @l.info "DELETE #{path}"

  response = @client.delete do |req|
    req.url path
    req.headers['X-HockeyAppToken'] = @token
  end

  response
end

#get(path) ⇒ Object

The http wrapper for GET method to the HockayApp. you might give a block object if necessary.


36
37
38
39
40
41
42
43
44
45
46
# File 'lib/hockeyhelper/networking.rb', line 36

def get(path)
  @l.info "GET #{path}"

  response = @client.get do |req|
    req.url path
    req.headers['X-HockeyAppToken'] = @token
    yield req if block_given?
  end

  response
end

#get_object(path) ⇒ Object

The http wrapper for GET method to the HockayApp. you might give a block object if necessary. see the #get method

Return the Hash object from response json.


53
54
55
56
# File 'lib/hockeyhelper/networking.rb', line 53

def get_object(path)
  response = get(path)
  JSON.parse(response.body) || {}
end

#post(path, bodyhash) ⇒ Object

The http wrapper for POST method to the HockayApp.


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

def post(path, bodyhash)
  @l.info "POST #{path}, #{bodyhash}"

  response = @client.post do |req|
    req.url path
    req.headers['X-HockeyAppToken'] = @token
    req.body = bodyhash
  end

  response
end

#post_object(path, bodyhash) ⇒ Object


71
72
73
74
# File 'lib/hockeyhelper/networking.rb', line 71

def post_object(path, bodyhash)
  response = post path, bodyhash
  JSON.parse(response.body) || {}
end