Class: Pod::CodingArUtil
- Inherits:
-
Object
- Object
- Pod::CodingArUtil
- Defined in:
- lib/coding_ar_util.rb
Constant Summary collapse
- CODING_AR_NETRC_PATH_ENV =
'COCOAPODS_CODING_AR_NETRC_PATH'
- JSON_CONTENT_TYPE =
'application/json; charset=utf-8'
- USER_AGENT =
"cocoapods-coding-ar/#{CocoapodsCodingAr::VERSION} cocoapods/#{Pod::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} (#{IO.popen('uname -v').gets.strip})"
Class Method Summary collapse
- .coding_ar_service?(url) ⇒ Boolean
- .download(url, path) ⇒ Object
- .get_json(url) ⇒ Object
- .push_pod(url, body_path) ⇒ Object
Class Method Details
.coding_ar_service?(url) ⇒ Boolean
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/coding_ar_util.rb', line 12 def self.coding_ar_service?(url) request = Typhoeus::Request.new( url, :method => :get, :headers => { 'User-Agent' => USER_AGENT, }, ) request.run begin resp = JSON.parse(request.response.body) resp['service'] == 'CODING-AR' rescue return false end end |
.download(url, path) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/coding_ar_util.rb', line 73 def self.download(url, path) request = Typhoeus::Request.new( url, :method => :get, :netrc => :optional, :netrc_file => ENV[CODING_AR_NETRC_PATH_ENV] || Netrc.default_path, :followlocation => true, :headers => { 'User-Agent' => USER_AGENT, }, ) request.run if request.response.code == 0 raise "fail to request #{url}: #{request.response.return_message}" elsif request.response.code != 200 raise "fail to request #{url}: #{request.response.body}" else file = File.new(path, 'wb') file << request.response.body file.close end end |
.get_json(url) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/coding_ar_util.rb', line 51 def self.get_json(url) request = Typhoeus::Request.new( url, :method => :get, :netrc => :optional, :netrc_file => ENV[CODING_AR_NETRC_PATH_ENV] || Netrc.default_path, :followlocation => true, :headers => { 'User-Agent' => USER_AGENT, }, ) request.run if request.response.code == 0 raise "fail to request #{url}: #{request.response.return_message}" elsif request.response.code != 200 raise "fail to request #{url}: #{request.response.body}" else JSON.parse(request.response.body) end end |
.push_pod(url, body_path) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/coding_ar_util.rb', line 30 def self.push_pod(url, body_path) request = Typhoeus::Request.new( url, :method => :post, :netrc => :optional, :netrc_file => ENV[CODING_AR_NETRC_PATH_ENV] || Netrc.default_path, :headers => { 'Content-Type' => JSON_CONTENT_TYPE, 'User-Agent' => USER_AGENT, }, :body => File.read(body_path), ) request.run if request.response.code == 0 raise "fail to push pod: #{request.response.return_message}" elsif request.response.code != 200 raise "fail to push pod: #{request.response.body}" end end |