mmjmenu 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mmjmenu.gemspec
4
+ gemspec
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mmjmenu (0.0.1)
5
+ fakeweb (>= 1.3.0)
6
+ hashie (~> 0.4.0)
7
+ httparty (~> 0.6.1)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ crack (0.1.8)
13
+ diff-lcs (1.1.2)
14
+ fakeweb (1.3.0)
15
+ hashie (0.4.0)
16
+ httparty (0.6.1)
17
+ crack (= 0.1.8)
18
+ rspec (2.0.1)
19
+ rspec-core (~> 2.0.1)
20
+ rspec-expectations (~> 2.0.1)
21
+ rspec-mocks (~> 2.0.1)
22
+ rspec-core (2.0.1)
23
+ rspec-expectations (2.0.1)
24
+ diff-lcs (>= 1.1.2)
25
+ rspec-mocks (2.0.1)
26
+ rspec-core (~> 2.0.1)
27
+ rspec-expectations (~> 2.0.1)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ fakeweb (>= 1.3.0)
34
+ hashie (~> 0.4.0)
35
+ httparty (~> 0.6.1)
36
+ mmjmenu!
37
+ rspec (~> 2.0.0.beta.22)
@@ -0,0 +1,22 @@
1
+ ## Installation
2
+
3
+ sudo gem install mmjmenu
4
+
5
+ ## Examples
6
+
7
+ ### List Menu Items
8
+ @client = Mmjmenu::Client.new('abc123')
9
+ @client.menu_items
10
+
11
+ ### List On-hold Menu Items
12
+ @client = Mmjmenu::Client.new('abc123')
13
+ @client.menu_items(:status => :on_hold)
14
+
15
+ ### Get a Menu Item
16
+ @client = Mmjmenu::Client.new('abc123')
17
+ @client.menu_item('12345')
18
+
19
+ ### List Unconfirmed Patients
20
+ @client = Mmjmenu::Client.new('abc123')
21
+ @client.unconfirmed_patients
22
+
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,12 @@
1
+ require 'hashie'
2
+ require 'httparty'
3
+ require 'json'
4
+
5
+ directory = File.expand_path(File.dirname(__FILE__))
6
+
7
+ Hash.send :include, Hashie::HashExtensions
8
+
9
+ require File.join(directory, 'mmjmenu', 'client')
10
+
11
+ module Mmjmenu
12
+ end
@@ -0,0 +1,82 @@
1
+ module Mmjmenu
2
+ class UnexpectedResponseError < RuntimeError
3
+ end
4
+
5
+ class Parser < HTTParty::Parser
6
+ def parse
7
+ begin
8
+ Crack::JSON.parse(body)
9
+ rescue => e
10
+ raise UnexpectedResponseError, "Crack could not parse JSON. It said: #{e.message}. Mmjmenu's raw response: #{body}"
11
+ end
12
+ end
13
+ end
14
+
15
+ class Client
16
+ include HTTParty
17
+
18
+ parser Mmjmenu::Parser
19
+ headers 'Content-Type' => 'application/json'
20
+
21
+ attr_reader :api_key
22
+
23
+ # Your API key can be generated on the options screen.
24
+ def initialize(api_key)
25
+ @api_key = api_key
26
+
27
+ self.class.base_uri "https://mmjmenu.com/api/v1"
28
+ self.class.basic_auth @api_key, 'x'
29
+
30
+ end
31
+
32
+ #Menu Items
33
+ def menu_items(options={})
34
+ options[:status] ||= 'active'
35
+ if options[:status].to_s.downcase == 'on_hold'
36
+ request = get("/menu_items/on_hold", :query => options)
37
+ else
38
+ request = get("/menu_items", :query => options)
39
+ end
40
+ request['menu_items'].map{|c| Hashie::Mash.new(c)}
41
+ end
42
+
43
+ def menu_item(menu_item_id, options={})
44
+ request = get("/menu_items/#{menu_item_id}")
45
+ success = request.code == 200
46
+ response = Hashie::Mash.new(request) if success
47
+ Hashie::Mash.new(response['menu_item'] || {}).update(:success? => success)
48
+ end
49
+
50
+ #Patients
51
+ def unconfirmed_patients(options = {})
52
+ request = get("/patients/unconfirmed", :query => options)
53
+ request['patients'].map{|c| Hashie::Mash.new(c)}
54
+ end
55
+
56
+ private
57
+
58
+ def post(path, options={})
59
+ jsonify_body!(options)
60
+ self.class.post(path, options)
61
+ end
62
+
63
+ def put(path, options={})
64
+ jsonify_body!(options)
65
+ self.class.put(path, options)
66
+ end
67
+
68
+ def delete(path, options={})
69
+ jsonify_body!(options)
70
+ self.class.delete(path, options)
71
+ end
72
+
73
+ def get(path, options={})
74
+ jsonify_body!(options)
75
+ self.class.get(path, options)
76
+ end
77
+
78
+ def jsonify_body!(options)
79
+ options[:body] = options[:body].to_json if options[:body]
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,3 @@
1
+ module Mmjmenu
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "mmjmenu/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mmjmenu"
7
+ s.version = Mmjmenu::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Justin Weidmann", "Alex Weidmann"]
10
+ s.email = ["justin@mmjmenu.com", "alex@mmjmenu.com"]
11
+ s.homepage = "http://rubygems.org/gems/mmjmenu"
12
+ s.summary = %q{Ruby wrapper for mmjmenu.com API}
13
+ s.description = %q{Ruby wrapper for mmjmenu.com API}
14
+
15
+ s.rubyforge_project = "mmjmenu"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency "rspec", "~> 2.0.0.beta.22"
23
+
24
+ s.add_dependency(%q<hashie>, ["~> 0.4.0"])
25
+ s.add_dependency(%q<httparty>, ["~> 0.6.1"])
26
+ s.add_dependency(%q<fakeweb>, [">= 1.3.0"])
27
+
28
+ end
@@ -0,0 +1,24 @@
1
+ {
2
+ "menu_item": {
3
+ "on_hold":false,
4
+ "sativa":0,
5
+ "thc_percent":0,
6
+ "cdn":0,
7
+ "updated_at":"2010-12-22T23:29:02-07:00",
8
+ "amount":3.0,
9
+ "cbd":0,
10
+ "genetics":null,
11
+ "body_html":"",
12
+ "created_at":"2010-08-09T15:58:08-07:00",
13
+ "name":"Kush",
14
+ "indica":0,
15
+ "id":3654,
16
+ "picture": {
17
+ "original":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_original.png",
18
+ "square":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_square.png",
19
+ "large":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_large.png",
20
+ "small":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_small.png",
21
+ "medium":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_medium.png"
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,49 @@
1
+
2
+ {
3
+ "menu_items": [
4
+ {
5
+ "on_hold":false,
6
+ "sativa":0,
7
+ "thc_percent":0,
8
+ "cdn":0,
9
+ "updated_at":"2010-12-22T23:29:02-07:00",
10
+ "amount":3.0,
11
+ "cbd":0,
12
+ "genetics":null,
13
+ "body_html":"",
14
+ "created_at":"2010-08-09T15:58:08-07:00",
15
+ "name":"Kush",
16
+ "indica":0,
17
+ "id":3654,
18
+ "picture": {
19
+ "original":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_original.png",
20
+ "square":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_square.png",
21
+ "large":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_large.png",
22
+ "small":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_small.png",
23
+ "medium":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_medium.png"
24
+ }
25
+ },
26
+ {
27
+ "on_hold":false,
28
+ "sativa":0,
29
+ "thc_percent":0,
30
+ "cdn":0,
31
+ "updated_at":"2010-12-22T23:29:02-07:00",
32
+ "amount":3.0,
33
+ "cbd":0,
34
+ "genetics":null,
35
+ "body_html":"",
36
+ "created_at":"2010-08-09T15:58:08-07:00",
37
+ "name":"Blueberry",
38
+ "indica":0,
39
+ "id":3654,
40
+ "picture": {
41
+ "original":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_original.png",
42
+ "square":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_square.png",
43
+ "large":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_large.png",
44
+ "small":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_small.png",
45
+ "medium":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_medium.png"
46
+ }
47
+ }
48
+ ]
49
+ }
@@ -0,0 +1,49 @@
1
+
2
+ {
3
+ "menu_items": [
4
+ {
5
+ "on_hold":true,
6
+ "sativa":0,
7
+ "thc_percent":0,
8
+ "cdn":0,
9
+ "updated_at":"2010-12-22T23:29:02-07:00",
10
+ "amount":3.0,
11
+ "cbd":0,
12
+ "genetics":null,
13
+ "body_html":"",
14
+ "created_at":"2010-08-09T15:58:08-07:00",
15
+ "name":"Kush Hold",
16
+ "indica":0,
17
+ "id":3654,
18
+ "picture": {
19
+ "original":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_original.png",
20
+ "square":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_square.png",
21
+ "large":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_large.png",
22
+ "small":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_small.png",
23
+ "medium":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_medium.png"
24
+ }
25
+ },
26
+ {
27
+ "on_hold":true,
28
+ "sativa":0,
29
+ "thc_percent":0,
30
+ "cdn":0,
31
+ "updated_at":"2010-12-22T23:29:02-07:00",
32
+ "amount":3.0,
33
+ "cbd":0,
34
+ "genetics":null,
35
+ "body_html":"",
36
+ "created_at":"2010-08-09T15:58:08-07:00",
37
+ "name":"Blueberry Hold",
38
+ "indica":0,
39
+ "id":3654,
40
+ "picture": {
41
+ "original":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_original.png",
42
+ "square":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_square.png",
43
+ "large":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_large.png",
44
+ "small":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_small.png",
45
+ "medium":"https://mmjmenu.com/images/attachments_missing/menu_items/images/missing_medium.png"
46
+ }
47
+ }
48
+ ]
49
+ }
@@ -0,0 +1,38 @@
1
+ {
2
+ "patients": [
3
+ {
4
+ "registry_no": "",
5
+ "address": "",
6
+ "city": "",
7
+ "card_expires_at": "",
8
+ "email": "",
9
+ "verification_number": "",
10
+ "dob": "",
11
+ "phone_number": "",
12
+ "verification_web": "",
13
+ "state": "",
14
+ "created_at": "2011-01-04T21:41:55-07:00",
15
+ "name": "Jane Doe",
16
+ "confirmed": false,
17
+ "id": 66506,
18
+ "zip_code": ""
19
+ },
20
+ {
21
+ "registry_no": "mmj123",
22
+ "address": "123 Osim Ville",
23
+ "city": "Denver",
24
+ "card_expires_at": "2020-01-01T00:00:00-07:00",
25
+ "email": "johdoe@jondoe.com",
26
+ "verification_number": "5555555555",
27
+ "dob": "1900-01-01T00:00:00-07:00",
28
+ "phone_number": "5555555555",
29
+ "verification_web": "www.web.com/verify2",
30
+ "state": "CO",
31
+ "created_at": "2011-01-11T17:11:44-07:00",
32
+ "name": "John Doe",
33
+ "confirmed": false,
34
+ "id": 66507,
35
+ "zip_code": "80222"
36
+ }
37
+ ]
38
+ }
@@ -0,0 +1,48 @@
1
+ #require 'pathname'
2
+
3
+ #require 'shoulda'
4
+ #require 'matchy'
5
+ #require 'mocha'
6
+ require 'fakeweb'
7
+ #require 'redgreen'
8
+
9
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
11
+ require 'mmjmenu'
12
+
13
+ FakeWeb.allow_net_connect = false
14
+
15
+ def fixture_file(filename)
16
+ return '' if filename == ''
17
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
18
+ File.read(file_path)
19
+ end
20
+
21
+
22
+ def stub_get(url, filename, status=nil)
23
+ options = {:body => fixture_file(filename)}
24
+ options.merge!({:status => status}) unless status.nil?
25
+
26
+ FakeWeb.register_uri(:get, url, options)
27
+ end
28
+
29
+ def stub_post(url, filename, status=nil)
30
+ options = {:body => fixture_file(filename)}
31
+ options.merge!({:status => status}) unless status.nil?
32
+
33
+ FakeWeb.register_uri(:post, url, options)
34
+ end
35
+
36
+ def stub_put(url, filename, status=nil)
37
+ options = {:body => fixture_file(filename)}
38
+ options.merge!({:status => status}) unless status.nil?
39
+
40
+ FakeWeb.register_uri(:put, url, options)
41
+ end
42
+
43
+ def stub_delete(url, filename, status=nil)
44
+ options = {:body => fixture_file(filename)}
45
+ options.merge!({:status => status}) unless status.nil?
46
+
47
+ FakeWeb.register_uri(:delete, url, options)
48
+ end
@@ -0,0 +1,48 @@
1
+ require 'helper'
2
+
3
+ describe "MMJMenu API client" do
4
+
5
+ before do
6
+ @client = Mmjmenu::Client.new('ABC123')
7
+ end
8
+
9
+ describe "Menu Items" do
10
+ it "should return a list of active menu items" do
11
+ stub_get "https://ABC123:x@mmjmenu.com/api/v1/menu_items?status=active", "menu_items.json"
12
+ menu_items = @client.menu_items
13
+ menu_items.size.should == 2
14
+ menu_items.first.name.should == 'Kush'
15
+ menu_items.first.on_hold.should == false
16
+ menu_items.last.name.should == 'Blueberry'
17
+ end
18
+
19
+ it "should return a list of on hold menu items" do
20
+ stub_get "https://ABC123:x@mmjmenu.com/api/v1/menu_items/on_hold?status=on_hold", "menu_items_on_hold.json"
21
+ menu_items = @client.menu_items(:status => 'on_hold')
22
+ menu_items.size.should == 2
23
+ menu_items.first.name.should == 'Kush Hold'
24
+ menu_items.first.on_hold.should == true
25
+ menu_items.last.name.should == 'Blueberry Hold'
26
+ end
27
+
28
+ it "should be able to find by a id" do
29
+ stub_get "https://ABC123:x@mmjmenu.com/api/v1/menu_items/10817", "menu_item.json"
30
+ menu_item = @client.menu_item(10817)
31
+ menu_item.success?.should == true
32
+ menu_item.name.should == 'Kush'
33
+ end
34
+ end
35
+
36
+ describe "Patients" do
37
+ it "should return a list of unconfirmed patients" do
38
+ stub_get "https://ABC123:x@mmjmenu.com/api/v1/patients/unconfirmed", "unconfirmed_patients.json"
39
+ patients = @client.unconfirmed_patients
40
+ patients.size.should == 2
41
+ patients.first.name.should == 'Jane Doe'
42
+ patients.first.confirmed.should == false
43
+ patients.last.name.should == 'John Doe'
44
+ end
45
+ end
46
+
47
+ end
48
+
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mmjmenu
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Justin Weidmann
13
+ - Alex Weidmann
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-13 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 2
31
+ - 0
32
+ - 0
33
+ - beta
34
+ - 22
35
+ version: 2.0.0.beta.22
36
+ type: :development
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: hashie
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ segments:
47
+ - 0
48
+ - 4
49
+ - 0
50
+ version: 0.4.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: httparty
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
63
+ - 6
64
+ - 1
65
+ version: 0.6.1
66
+ type: :runtime
67
+ version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ name: fakeweb
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 1
78
+ - 3
79
+ - 0
80
+ version: 1.3.0
81
+ type: :runtime
82
+ version_requirements: *id004
83
+ description: Ruby wrapper for mmjmenu.com API
84
+ email:
85
+ - justin@mmjmenu.com
86
+ - alex@mmjmenu.com
87
+ executables: []
88
+
89
+ extensions: []
90
+
91
+ extra_rdoc_files: []
92
+
93
+ files:
94
+ - .gitignore
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - README.markdown
98
+ - Rakefile
99
+ - lib/mmjmenu.rb
100
+ - lib/mmjmenu/client.rb
101
+ - lib/mmjmenu/version.rb
102
+ - mmjmenu.gemspec
103
+ - spec/fixtures/menu_item.json
104
+ - spec/fixtures/menu_items.json
105
+ - spec/fixtures/menu_items_on_hold.json
106
+ - spec/fixtures/unconfirmed_patients.json
107
+ - spec/helper.rb
108
+ - spec/mmjmenu_spec.rb
109
+ has_rdoc: true
110
+ homepage: http://rubygems.org/gems/mmjmenu
111
+ licenses: []
112
+
113
+ post_install_message:
114
+ rdoc_options: []
115
+
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ requirements: []
135
+
136
+ rubyforge_project: mmjmenu
137
+ rubygems_version: 1.3.7
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: Ruby wrapper for mmjmenu.com API
141
+ test_files: []
142
+