pearson_kitchen_manager 0.0.1
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.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +52 -0
- data/Rakefile +4 -0
- data/lib/pearson_kitchen_manager/version.rb +3 -0
- data/lib/pearson_kitchen_manager.rb +105 -0
- data/pearson_kitchen_manager.gemspec +23 -0
- data/spec/pearson_kitchen_manager_spec.rb +43 -0
- data/spec/spec_helper.rb +23 -0
- metadata +121 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Dave Shapiro
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# PearsonKitchenManager
|
2
|
+
|
3
|
+
API wrapper for Pearson Kitchen Manager
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'pearson_kitchen_manager'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install pearson_kitchen_manager
|
18
|
+
|
19
|
+
##Requirements
|
20
|
+
|
21
|
+
A Pearson account and API key. You can see your API keys [here](http://developer.pearson.com/sdm/myprofile).
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
pkm = PearsonKitchenManager.new("your_api_key")
|
26
|
+
|
27
|
+
> Note: In an effort to simplify PearsonKitchenManager, you can use 'MAILCHIMP_API_KEY' in the environment variable instead of passing it.
|
28
|
+
Fetching data is as simple as calling API methods directly on the wrapper
|
29
|
+
object. The API calls may be made with either camelcase or underscore
|
30
|
+
separated formatting as you see in the "More Advanced Examples" section below.
|
31
|
+
|
32
|
+
Check the API [documentation](http://developer.pearson.com/api/pearson-kitchen-manager/apimethod/courses/190/overview) for details.
|
33
|
+
|
34
|
+
### Fetching Recipes
|
35
|
+
|
36
|
+
For example, to fetch your first 100 recipes (offset 0):
|
37
|
+
|
38
|
+
recipes = pkm.recipes({offset: 0, limit: 100})
|
39
|
+
|
40
|
+
### Fetching Recipe
|
41
|
+
|
42
|
+
For example, to fetch your first 100 recipes (offset 0):
|
43
|
+
|
44
|
+
recipe = pkm.recipes(url_extension: "recipe_id")
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
class PearsonKitchenManager
|
6
|
+
include HTTParty
|
7
|
+
debug_output $stderr
|
8
|
+
|
9
|
+
format :plain
|
10
|
+
default_timeout 30
|
11
|
+
|
12
|
+
attr_accessor :api_key, :timeout
|
13
|
+
|
14
|
+
def initialize(api_key = nil, extra_params = {})
|
15
|
+
@api_key = api_key || ENV['PEARSON_API_KEY'] || self.class.api_key
|
16
|
+
@default_params = {:apikey => @api_key}.merge(extra_params)
|
17
|
+
end
|
18
|
+
|
19
|
+
def api_key=(value)
|
20
|
+
@api_key = value
|
21
|
+
@default_params = @default_params.merge({:apikey => @api_key})
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_exporter
|
25
|
+
GibbonExport.new(@api_key, @default_params)
|
26
|
+
end
|
27
|
+
|
28
|
+
def base_api_url
|
29
|
+
"http://api.pearson.com/kitchen-manager/v1/"
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
def call(method, params = {})
|
34
|
+
api_url = base_api_url + method
|
35
|
+
|
36
|
+
if params.keys.include?(:url_extension)
|
37
|
+
api_url << "/" << params.delete(:url_extension)
|
38
|
+
end
|
39
|
+
|
40
|
+
params = @default_params.merge(params)
|
41
|
+
response = self.class.get(api_url, :query => params.collect{|k, v| HTTParty::HashConversions.normalize_param(k, v)}.join(), :timeout => @timeout)
|
42
|
+
|
43
|
+
|
44
|
+
# Some calls (e.g. recipes) return json fragments
|
45
|
+
# (e.g. true) so wrap in an array prior to parsing
|
46
|
+
response = JSON.parse('['+response.body+']').first
|
47
|
+
|
48
|
+
if response = "Access Denied"
|
49
|
+
raise "Error from Pearson Kitchen Manager API: #{response}"
|
50
|
+
end
|
51
|
+
|
52
|
+
response
|
53
|
+
end
|
54
|
+
|
55
|
+
def method_missing(method, *args)
|
56
|
+
method = method.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } #Thanks for the gsub, Rails
|
57
|
+
method = method[0].chr.downcase + method[1..-1].gsub(/aim$/i, 'AIM')
|
58
|
+
call(method, *args)
|
59
|
+
end
|
60
|
+
|
61
|
+
class << self
|
62
|
+
attr_accessor :api_key
|
63
|
+
|
64
|
+
def method_missing(sym, *args, &block)
|
65
|
+
new(self.api_key).send(sym, *args, &block)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
module HTTParty
|
73
|
+
module HashConversions
|
74
|
+
# @param key<Object> The key for the param.
|
75
|
+
# @param value<Object> The value for the param.
|
76
|
+
#
|
77
|
+
# @return <String> This key value pair as a param
|
78
|
+
#
|
79
|
+
# @example normalize_param(:name, "Bob Jones") #=> "name=Bob%20Jones&"
|
80
|
+
def self.normalize_param(key, value)
|
81
|
+
param = ''
|
82
|
+
stack = []
|
83
|
+
|
84
|
+
if value.is_a?(Array)
|
85
|
+
param << Hash[*(0...value.length).to_a.zip(value).flatten].map {|i,element| normalize_param("#{key}[#{i}]", element)}.join
|
86
|
+
elsif value.is_a?(Hash)
|
87
|
+
stack << [key,value]
|
88
|
+
else
|
89
|
+
param << "#{key}=#{URI.encode(value.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}&"
|
90
|
+
end
|
91
|
+
|
92
|
+
stack.each do |parent, hash|
|
93
|
+
hash.each do |key, value|
|
94
|
+
if value.is_a?(Hash)
|
95
|
+
stack << ["#{parent}[#{key}]", value]
|
96
|
+
else
|
97
|
+
param << normalize_param("#{parent}[#{key}]", value)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
param
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/pearson_kitchen_manager/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Dave Shapiro"]
|
6
|
+
gem.email = ["dss.shapiro@gmail.com"]
|
7
|
+
gem.description = %q{API wrapper for Pearson Kitchen Manager}
|
8
|
+
gem.summary = %q{API wrapper for Pearson Kitchen Manager}
|
9
|
+
gem.homepage = "https://github.com/dsshap/pearson_kitchen_manager"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
# gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "pearson_kitchen_manager"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = PearsonKitchenManager::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency('httparty')
|
19
|
+
gem.add_dependency('json')
|
20
|
+
|
21
|
+
gem.add_development_dependency('debugger')
|
22
|
+
gem.add_development_dependency("rspec")
|
23
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PearsonKitchenManager do
|
4
|
+
|
5
|
+
before do
|
6
|
+
ENV['PEARSON_API_KEY'] = "60e048c10b333c8dc25a6d85470ca653"
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'basics to hit api' do
|
10
|
+
|
11
|
+
it "should get api key from env vars" do
|
12
|
+
ENV['PEARSON_API_KEY'].should eq("60e048c10b333c8dc25a6d85470ca653")
|
13
|
+
end
|
14
|
+
|
15
|
+
# it "should connect to service" do
|
16
|
+
# pkm = PearsonKitchenManager.new
|
17
|
+
# pkm.courses.should_not
|
18
|
+
# end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'recipes' do
|
23
|
+
|
24
|
+
# it 'should get recipes' do
|
25
|
+
# pkm = PearsonKitchenManager.new
|
26
|
+
# response = pkm.recipes
|
27
|
+
# response['results'].count.should eq(10)
|
28
|
+
# end
|
29
|
+
|
30
|
+
it 'should get a recipe' do
|
31
|
+
pkm = PearsonKitchenManager.new
|
32
|
+
# response = pkm.recipes
|
33
|
+
|
34
|
+
# recipe = response['results'].first
|
35
|
+
|
36
|
+
response = pkm.recipes(url_extension: "albufera-sauce")
|
37
|
+
|
38
|
+
puts "response: #{response.to_json}"
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require 'rspec'
|
9
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
10
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
11
|
+
require 'pearson_kitchen_manager'
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
15
|
+
config.run_all_when_everything_filtered = true
|
16
|
+
config.filter_run :focus
|
17
|
+
|
18
|
+
# Run specs in random order to surface order dependencies. If you find an
|
19
|
+
# order dependency and want to debug it, you can fix the order by providing
|
20
|
+
# the seed, which is printed after each run.
|
21
|
+
# --seed 1234
|
22
|
+
config.order = 'random'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pearson_kitchen_manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dave Shapiro
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: debugger
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: API wrapper for Pearson Kitchen Manager
|
79
|
+
email:
|
80
|
+
- dss.shapiro@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- .rspec
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- lib/pearson_kitchen_manager.rb
|
92
|
+
- lib/pearson_kitchen_manager/version.rb
|
93
|
+
- pearson_kitchen_manager.gemspec
|
94
|
+
- spec/pearson_kitchen_manager_spec.rb
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
homepage: https://github.com/dsshap/pearson_kitchen_manager
|
97
|
+
licenses: []
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 1.8.24
|
117
|
+
signing_key:
|
118
|
+
specification_version: 3
|
119
|
+
summary: API wrapper for Pearson Kitchen Manager
|
120
|
+
test_files: []
|
121
|
+
has_rdoc:
|