pearson_kitchen_manager 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,11 +39,11 @@ protected
|
|
39
39
|
if params.keys.include?(:url_extension)
|
40
40
|
api_url << "/" << params.delete(:url_extension)
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
params = @default_params.merge(params)
|
44
|
-
response = self.class.get(api_url, :query => params.collect{|k, v|
|
44
|
+
response = self.class.get(api_url, :query => params.collect{|k, v| normalize_param(k, v)}.join(), :timeout => @timeout)
|
45
|
+
|
45
46
|
|
46
|
-
|
47
47
|
# Some calls (e.g. recipes) return json fragments
|
48
48
|
# (e.g. true) so wrap in an array prior to parsing
|
49
49
|
response = JSON.parse('['+response.body+']').first
|
@@ -55,6 +55,31 @@ protected
|
|
55
55
|
response
|
56
56
|
end
|
57
57
|
|
58
|
+
def normalize_param(key, value)
|
59
|
+
param = ''
|
60
|
+
stack = []
|
61
|
+
|
62
|
+
if value.is_a?(Array)
|
63
|
+
param << Hash[*(0...value.length).to_a.zip(value).flatten].map {|i,element| normalize_param("#{key}[#{i}]", element)}.join
|
64
|
+
elsif value.is_a?(Hash)
|
65
|
+
stack << [key,value]
|
66
|
+
else
|
67
|
+
param << "#{key}=#{URI.encode(value.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}&"
|
68
|
+
end
|
69
|
+
|
70
|
+
stack.each do |parent, hash|
|
71
|
+
hash.each do |key, value|
|
72
|
+
if value.is_a?(Hash)
|
73
|
+
stack << ["#{parent}[#{key}]", value]
|
74
|
+
else
|
75
|
+
param << normalize_param("#{parent}[#{key}]", value)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
param
|
81
|
+
end
|
82
|
+
|
58
83
|
def method_missing(method, *args)
|
59
84
|
method = method.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } #Thanks for the gsub, Rails
|
60
85
|
method = method[0].chr.downcase + method[1..-1].gsub(/aim$/i, 'AIM')
|
@@ -70,7 +95,7 @@ protected
|
|
70
95
|
end
|
71
96
|
|
72
97
|
end
|
73
|
-
|
98
|
+
|
74
99
|
|
75
100
|
module HTTParty
|
76
101
|
module HashConversions
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0.
|
1
|
+
class PearsonKitchenManager
|
2
|
+
VERSION = "0.0.5"
|
3
3
|
end
|
@@ -3,13 +3,13 @@ require 'spec_helper'
|
|
3
3
|
describe PearsonKitchenManager do
|
4
4
|
|
5
5
|
before do
|
6
|
-
ENV['PEARSON_API_KEY'] = "
|
6
|
+
ENV['PEARSON_API_KEY'] = "60654073c99826491dcc34041057e7eb"
|
7
7
|
end
|
8
8
|
|
9
|
-
context 'basics to hit api' do
|
9
|
+
context 'basics to hit api' do
|
10
10
|
|
11
11
|
it "should get api key from env vars" do
|
12
|
-
ENV['PEARSON_API_KEY'].should eq("
|
12
|
+
ENV['PEARSON_API_KEY'].should eq("60654073c99826491dcc34041057e7eb")
|
13
13
|
end
|
14
14
|
|
15
15
|
# it "should connect to service" do
|
@@ -17,7 +17,7 @@ describe PearsonKitchenManager do
|
|
17
17
|
# pkm.courses.should_not
|
18
18
|
# end
|
19
19
|
|
20
|
-
end
|
20
|
+
end
|
21
21
|
|
22
22
|
context 'recipes' do
|
23
23
|
|
@@ -33,7 +33,7 @@ describe PearsonKitchenManager do
|
|
33
33
|
|
34
34
|
# recipe = response['results'].first
|
35
35
|
|
36
|
-
response = pkm.recipes(url_extension: "
|
36
|
+
response = pkm.recipes(url_extension: "hungarian-cucumber-salad")
|
37
37
|
|
38
38
|
puts "response: #{response.to_json}"
|
39
39
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pearson_kitchen_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|