grifter 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4b156d151835e6627b686b679baf97d38618dc1
4
- data.tar.gz: 08cb91638ad50478b0f94eeaf136afe51214af54
3
+ metadata.gz: 272206b2927fd805a4d0eebfaeb12aa9bb5544b8
4
+ data.tar.gz: 811ddf5f1872f2c8a82a0ccf7fb5082d7d5537ac
5
5
  SHA512:
6
- metadata.gz: 91807edba6321e443c70456ec51df0aa1f80ee6e2edb0eb2ca7cf8ed9501a7eed4b3e067a92de48856dd0837448035e5417e4eb231bef9ca5f233d9e0c97d7fe
7
- data.tar.gz: c156a39a751881f891fe7fcb4bf79f880e2f40a1b546342fc862986926149dd997030c974816e047cf18092430bf7c68f869f669bb39e93eae184e8e4f287425
6
+ metadata.gz: e687565405a56497e50a449267895dc594006df2ae3679034003fc24132937fab025a76f3204e1707af89a8456c661b50a9766bec55d50b02343221262874759
7
+ data.tar.gz: 4aaf0eda705b509714ffbcb3b02d2d06df44dbf3645ebb412ccc6bb20dcef047bfac5693815bedfa4b26421689480cc432080e150931896031bf9a146418914f
data/Readme.md CHANGED
@@ -57,7 +57,7 @@ which is accessible without needing any authentication key:
57
57
  mkdir owm_grifts
58
58
  touch owm_grifts/weather_grifts.rb
59
59
 
60
- ### add method for checking weather to owm/weather.rb
60
+ ### add method for checking weather to owm_grifts/weather.rb
61
61
  def weather_for city
62
62
  owm.get "/data/2.5/weather?q=#{URI.encode(city)}"
63
63
  end
@@ -118,7 +118,8 @@ Setup spec/weather_spec.rb with contents like:
118
118
  describe "getting weather reports" do
119
119
  it "should know the weather for New York City" do
120
120
  response = weather_for 'New York, NY'
121
- response['main'].keys.should =~ ['temp', 'temp_min', 'temp_max', 'humidity', 'pressure']
121
+ expected_items = ['temp', 'temp_min', 'temp_max', 'humidity', 'pressure']
122
+ response['main'].keys.should include(*expected_items)
122
123
  end
123
124
  end
124
125
 
data/bin/grift CHANGED
@@ -46,6 +46,11 @@ def parse_cmd_line
46
46
  opts.on("-n", "--no-authenticate",
47
47
  "Do not authenticate") { options[:authenticate] = false }
48
48
 
49
+ opts.on('-l', "--list", "Print each available grift method") do
50
+ options[:list_grift_methods] = true
51
+ options[:authenticate] = false #no point in authenticating for --list
52
+ end
53
+
49
54
  end
50
55
  optparse.parse!
51
56
  options
@@ -66,6 +71,17 @@ rescue GrifterConfigFileMissing => e
66
71
  Kernel.abort
67
72
  end
68
73
 
74
+ if options[:list_grift_methods]
75
+ puts "Grift method listing"
76
+
77
+ grifter.singleton_methods.sort.each do |meth|
78
+ puts " - #{meth}(#{grifter.method(meth).parameters.join(', ')})"
79
+
80
+ end
81
+
82
+ exit
83
+ end
84
+
69
85
  if not(ARGV.empty?)
70
86
  #a grift method has been specified on the command line
71
87
  method = ARGV.shift
data/grifter.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "grifter"
8
- s.version = "0.1.2"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Robert Schultheis"]
12
- s.date = "2013-10-07"
12
+ s.date = "2013-11-05"
13
13
  s.description = "convention based approach to interfacing with an HTTP JSON API."
14
14
  s.email = "rob@knewton.com"
15
15
  s.executables = ["grift"]
@@ -1,4 +1,5 @@
1
1
  require 'yaml'
2
+ require 'uri'
2
3
 
3
4
  require_relative 'log'
4
5
 
@@ -16,6 +17,20 @@ class Grifter
16
17
  end
17
18
  end
18
19
 
20
+ def get_service_config_from_url url
21
+ return {} if url.nil?
22
+ unless url =~ URI::ABS_URI
23
+ raise GrifterConfigurationError.new "url is not a proper aboslute URL: #{url}"
24
+ end
25
+ parsed = URI.parse url
26
+ {
27
+ :hostname => parsed.host,
28
+ :port => parsed.port,
29
+ :base_uri => parsed.path,
30
+ :ssl => (parsed.scheme == 'https'),
31
+ }
32
+ end
33
+
19
34
  def load_config_file options={}
20
35
  options = {
21
36
  config_file: ENV['GRIFTER_CONFIG_FILE'] ? ENV['GRIFTER_CONFIG_FILE'] : 'grifter.yml',
@@ -42,28 +57,17 @@ class Grifter
42
57
  #fill out services block entirely for each service
43
58
  config[:services].each_pair do |service_name, service_config|
44
59
  service_config[:name] = service_name.to_s
45
- #setup port config
46
- unless service_config[:port]
47
- if service_config[:ssl]
48
- service_config[:port] = 443
49
- else
50
- service_config[:port] = 80
51
- end
52
- end
53
-
54
- #ssl config
55
- unless service_config[:ssl]
56
- service_config[:ssl] = false
57
- end
58
-
59
- #ignore_ssl_certificate
60
- unless service_config[:ignore_ssl_cert]
61
- service_config[:ignore_ssl_cert] = false
62
- end
63
-
64
- unless service_config[:base_uri]
65
- service_config[:base_uri] = ''
66
- end
60
+
61
+ #check for a url configuration option. This option will trump any others that may be set
62
+ service_config.merge!(get_service_config_from_url(service_config.delete(:url)))
63
+
64
+ #default everything that is not defined
65
+ service_config.merge!({
66
+ ssl: false,
67
+ ignore_ssl_cert: false,
68
+ base_uri: '',
69
+ port: (service_config[:ssl] == true ? 443 : 80),
70
+ }.merge(service_config))
67
71
 
68
72
  end
69
73
 
@@ -75,12 +79,22 @@ class Grifter
75
79
  end
76
80
 
77
81
  config[:environments][config[:environment]].each_pair do |service_name, service_overrides|
82
+ service_overrides.merge!(get_service_config_from_url(service_overrides.delete(:url)))
78
83
  config[:services][service_name].merge! service_overrides
79
84
  end
80
85
  else
81
86
  config[:environment] = :undefined
82
87
  end
83
88
 
89
+ #merge any overrides provided via a GRIFTER_<svc name>_URL environment variable
90
+ config[:services].each_pair do |service_name, service_config|
91
+ env_var_name = "GRIFTER_#{service_config[:name].upcase}_URL"
92
+ if ENV[env_var_name]
93
+ Log.warn "Environment variable #{env_var_name} is defined, using it to override configuration"
94
+ service_config.merge!(get_service_config_from_url(ENV[env_var_name]))
95
+ end
96
+ end
97
+
84
98
  #join the grift globs with the relative path to config file
85
99
  if config[:grift_globs] && options[:config_file]
86
100
  config_file_dir = File.dirname options[:config_file]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grifter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Schultheis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-07 00:00:00.000000000 Z
11
+ date: 2013-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json