Module: Rubygems::API::Utilities
- Included in:
- Client
- Defined in:
- lib/rubygems_api/utilities.rb
Overview
The Utilities module allows us to use the same functions throughout
Instance Method Summary collapse
- #format_body(args = {}) ⇒ Object
- #format_json_body(response) ⇒ Object
- #format_yaml_body(response) ⇒ Object
- #get(url, format, hash, args = {}) ⇒ Object
- #ssl(arguments) ⇒ Object
- #validate_format(format) ⇒ Object
- #yank_api(url, method_symbol, gem_name, gem_version, args = {}) ⇒ Object
Instance Method Details
#format_body(args = {}) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/rubygems_api/utilities.rb', line 12 def format_body(args = {}) if args[:skip_format].nil? response = format_json_body(args[:response]) if args[:format] == 'json' response = format_yaml_body(args[:response]) if args[:format] == 'yaml' end response end |
#format_json_body(response) ⇒ Object
21 22 23 24 25 |
# File 'lib/rubygems_api/utilities.rb', line 21 def format_json_body(response) response.body = JSON.parse(response.body) response end |
#format_yaml_body(response) ⇒ Object
27 28 29 30 31 |
# File 'lib/rubygems_api/utilities.rb', line 27 def format_yaml_body(response) response.body = YAML.load(response.body) response end |
#get(url, format, hash, args = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rubygems_api/utilities.rb', line 48 def get(url, format, hash, args = {}) if validate_format format response = @client.get(url, hash) format_body response: response, skip_format: args[:skip_format], format: format if response.success? end response end |
#ssl(arguments) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rubygems_api/utilities.rb', line 33 def ssl(arguments) @skip_verification = arguments[:skip_verification] || \ true @ca_path = arguments[:ca_path] || \ `openssl version -d`.split(/"/)[1] + '/certs' @ssl_version = arguments[:ssl_version] || \ 'SSLv23' @client..skip_verification = @skip_verification @client..ca_path = @ca_path @client..version = @ssl_version end |
#validate_format(format) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/rubygems_api/utilities.rb', line 5 def validate_format(format) return true if format == 'json' || format == 'yaml' fail RuntimeError, 'Invalid format requested. Please select either json or yaml.' end |
#yank_api(url, method_symbol, gem_name, gem_version, args = {}) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/rubygems_api/utilities.rb', line 59 def yank_api(url, method_symbol, gem_name, gem_version, args = {}) response = @client.method(method_symbol).call(url, {}.tap do |hash| hash[:gem_name] = gem_name hash[:gem_version] = gem_version unless gem_version.nil? hash[:platform] = args[:platform] unless args[:platform].nil? end) response end |