Class: Veyor::Request
- Inherits:
-
Object
- Object
- Veyor::Request
- Defined in:
- lib/veyor/request.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#body ⇒ Object
Returns the value of attribute body.
-
#options ⇒ Object
Returns the value of attribute options.
-
#route ⇒ Object
Returns the value of attribute route.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #_veyor_delete(route) ⇒ Object
- #_veyor_get(route, opts) ⇒ Object
- #_veyor_post(route, body) ⇒ Object
- #delete ⇒ Object
- #get ⇒ Object
- #get_conn ⇒ Object
-
#initialize(route, args, body, options, verbose) ⇒ Request
constructor
A new instance of Request.
- #parse_result(z) ⇒ Object
- #post ⇒ Object
Constructor Details
#initialize(route, args, body, options, verbose) ⇒ Request
Returns a new instance of Request.
75 76 77 78 79 80 81 |
# File 'lib/veyor/request.rb', line 75 def initialize(route, args, body, , verbose) self.route = route self.args = args self.body = body self. = self.verbose = verbose end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
70 71 72 |
# File 'lib/veyor/request.rb', line 70 def args @args end |
#body ⇒ Object
Returns the value of attribute body.
71 72 73 |
# File 'lib/veyor/request.rb', line 71 def body @body end |
#options ⇒ Object
Returns the value of attribute options.
72 73 74 |
# File 'lib/veyor/request.rb', line 72 def @options end |
#route ⇒ Object
Returns the value of attribute route.
69 70 71 |
# File 'lib/veyor/request.rb', line 69 def route @route end |
#verbose ⇒ Object
Returns the value of attribute verbose.
73 74 75 |
# File 'lib/veyor/request.rb', line 73 def verbose @verbose end |
Instance Method Details
#_veyor_delete(route) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/veyor/request.rb', line 133 def _veyor_delete(route) tok = Veyor.account_token if tok.nil? raise 'could not find env var APPVEYOR_API_TOKEN; please set it' end conn = get_conn conn.delete do |req| req.url '/api/' + route req.headers["Authorization"] = "Bearer " + tok end end |
#_veyor_get(route, opts) ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/veyor/request.rb', line 108 def _veyor_get(route, opts) tok = Veyor.account_token conn = get_conn conn.get do |req| req.url '/api/' + route req.params = opts req.headers["Content-Type"] = "application/json" req.headers["Authorization"] = "Bearer " + tok if tok end end |
#_veyor_post(route, body) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/veyor/request.rb', line 119 def _veyor_post(route, body) tok = Veyor.account_token if tok.nil? raise 'could not find env var APPVEYOR_API_TOKEN; please set it' end conn = get_conn conn.post do |req| req.url '/api/' + route req.body = MultiJson.dump(body) req.headers["Content-Type"] = "application/json" req.headers["Authorization"] = "Bearer " + tok end end |
#delete ⇒ Object
163 164 165 |
# File 'lib/veyor/request.rb', line 163 def delete return _veyor_delete(self.route).status end |
#get ⇒ Object
153 154 155 156 |
# File 'lib/veyor/request.rb', line 153 def get res = _veyor_get(self.route, self.args) return parse_result(res) end |
#get_conn ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/veyor/request.rb', line 83 def get_conn # if args.nil? # args = {} # end if self.verbose conn = Faraday.new(:url => Veyor.base_url, :request => self.) do |f| f.request :url_encoded f.response :logger f.use CustomErrors f.adapter Faraday.default_adapter end else conn = Faraday.new(:url => Veyor.base_url, :request => self.) do |f| f.request :url_encoded f.use CustomErrors f.adapter Faraday.default_adapter end end conn.headers[:user_agent] = make_ua conn.headers["X-USER-AGENT"] = make_ua return conn end |
#parse_result(z) ⇒ Object
145 146 147 148 149 150 151 |
# File 'lib/veyor/request.rb', line 145 def parse_result(z) if z.headers['content-type'].match('json').nil? return z.body else return MultiJson.load(z.body) end end |
#post ⇒ Object
158 159 160 161 |
# File 'lib/veyor/request.rb', line 158 def post res = _veyor_post(self.route, self.body) return parse_result(res) end |