CatchNotes_api 0.1.2
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/.document +5 -0
- data/.gitignore +21 -0
- data/CatchNotes_api.gemspec +69 -0
- data/LICENSE +20 -0
- data/README.rdoc +41 -0
- data/Rakefile +58 -0
- data/VERSION +1 -0
- data/lib/catch_notes/base.rb +191 -0
- data/lib/catch_notes/errors.rb +14 -0
- data/lib/catch_notes.rb +5 -0
- data/test/faker.rb +96 -0
- data/test/helper.rb +12 -0
- data/test/note_class.rb +18 -0
- data/test/test_catch_notes.rb +91 -0
- metadata +145 -0
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{CatchNotes_api}
|
8
|
+
s.version = "0.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Wade West"]
|
12
|
+
s.date = %q{2010-11-05}
|
13
|
+
s.description = %q{An ActiveResource like interface to catch.com}
|
14
|
+
s.email = %q{wwest81@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"CatchNotes_api.gemspec",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/catch_notes.rb",
|
28
|
+
"lib/catch_notes/base.rb",
|
29
|
+
"lib/catch_notes/errors.rb",
|
30
|
+
"test/faker.rb",
|
31
|
+
"test/helper.rb",
|
32
|
+
"test/note_class.rb",
|
33
|
+
"test/test_catch_notes.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/wadewest/CatchNotes_api}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.7}
|
39
|
+
s.summary = %q{An ActiveResource like interface to catch.com}
|
40
|
+
s.test_files = [
|
41
|
+
"test/faker.rb",
|
42
|
+
"test/helper.rb",
|
43
|
+
"test/note_class.rb",
|
44
|
+
"test/test_catch_notes.rb"
|
45
|
+
]
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
|
53
|
+
s.add_runtime_dependency(%q<json>, [">= 1.4.6"])
|
54
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<sinatra>, [">= 1.1.0"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
58
|
+
s.add_dependency(%q<json>, [">= 1.4.6"])
|
59
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
60
|
+
s.add_dependency(%q<sinatra>, [">= 1.1.0"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
64
|
+
s.add_dependency(%q<json>, [">= 1.4.6"])
|
65
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
66
|
+
s.add_dependency(%q<sinatra>, [">= 1.1.0"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Wade West
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
= CatchNotes_api
|
2
|
+
|
3
|
+
== Usage
|
4
|
+
|
5
|
+
# setting up your note class
|
6
|
+
class Note < CatchNotes::Base
|
7
|
+
username 'foo@example.com'
|
8
|
+
password 'foobar'
|
9
|
+
end
|
10
|
+
|
11
|
+
# finding notes
|
12
|
+
notes = Note.all # returns an array of Note objects
|
13
|
+
first = Note.first # same as Note.all.first
|
14
|
+
last = Note.last # same as Note.all.last
|
15
|
+
|
16
|
+
first.text # the text content of the note
|
17
|
+
|
18
|
+
# creating notes
|
19
|
+
note = Note.new :text => "My New Note"
|
20
|
+
note.save # will return true if all is good
|
21
|
+
|
22
|
+
# updating a note
|
23
|
+
note.text = "My Updated Note"
|
24
|
+
note.save
|
25
|
+
|
26
|
+
# deleting a note
|
27
|
+
note.destroy # will return true if all is good
|
28
|
+
|
29
|
+
== Note on Patches/Pull Requests
|
30
|
+
|
31
|
+
* Fork the project.
|
32
|
+
* Make your feature addition or bug fix.
|
33
|
+
* Add tests for it. This is important so I don't break it in a
|
34
|
+
future version unintentionally.
|
35
|
+
* Commit, do not mess with rakefile, version, or history.
|
36
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
37
|
+
* Send me a pull request. Bonus points for topic branches.
|
38
|
+
|
39
|
+
== Copyright
|
40
|
+
|
41
|
+
Copyright (c) 2010 Wade West. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "CatchNotes_api"
|
8
|
+
gem.summary = %Q{An ActiveResource like interface to catch.com}
|
9
|
+
gem.description = %Q{An ActiveResource like interface to catch.com}
|
10
|
+
gem.email = "wwest81@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/wadewest/CatchNotes_api"
|
12
|
+
gem.authors = ["Wade West"]
|
13
|
+
|
14
|
+
gem.add_dependency 'httparty', '>=0.6.1'
|
15
|
+
gem.add_dependency 'json', '>=1.4.6'
|
16
|
+
|
17
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
18
|
+
gem.add_development_dependency "sinatra", ">= 1.1.0"
|
19
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
20
|
+
end
|
21
|
+
Jeweler::GemcutterTasks.new
|
22
|
+
rescue LoadError
|
23
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'rake/testtask'
|
27
|
+
Rake::TestTask.new(:test) do |test|
|
28
|
+
test.libs << 'lib' << 'test'
|
29
|
+
test.pattern = 'test/**/test_*.rb'
|
30
|
+
test.verbose = true
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
require 'rcov/rcovtask'
|
35
|
+
Rcov::RcovTask.new do |test|
|
36
|
+
test.libs << 'test'
|
37
|
+
test.pattern = 'test/**/test_*.rb'
|
38
|
+
test.verbose = true
|
39
|
+
end
|
40
|
+
rescue LoadError
|
41
|
+
task :rcov do
|
42
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
task :test => :check_dependencies
|
47
|
+
|
48
|
+
task :default => :test
|
49
|
+
|
50
|
+
require 'rake/rdoctask'
|
51
|
+
Rake::RDocTask.new do |rdoc|
|
52
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
53
|
+
|
54
|
+
rdoc.rdoc_dir = 'rdoc'
|
55
|
+
rdoc.title = "CatchNotes_api #{version}"
|
56
|
+
rdoc.rdoc_files.include('README*')
|
57
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
58
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.2
|
@@ -0,0 +1,191 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
module CatchNotes
|
4
|
+
class Base
|
5
|
+
|
6
|
+
attr_reader :id, :created_at, :modified_at, :source, :source_url,
|
7
|
+
:children, :user_name, :user_id
|
8
|
+
attr_accessor :text, :summary, :tags, :reminder_at, :location
|
9
|
+
|
10
|
+
include HTTParty
|
11
|
+
base_uri "https://api.catch.com/v1"
|
12
|
+
|
13
|
+
# Methods for Authenication
|
14
|
+
module AuthItems
|
15
|
+
module ClassMethods
|
16
|
+
def username( username )
|
17
|
+
send(:basic_auth, username, get_auth[:password] || '')
|
18
|
+
end
|
19
|
+
|
20
|
+
def password( password )
|
21
|
+
send(:basic_auth, get_auth[:username] || '', password)
|
22
|
+
end
|
23
|
+
|
24
|
+
def valid_username?
|
25
|
+
username = get_auth[:username]
|
26
|
+
!(username.nil? || username == '')
|
27
|
+
end
|
28
|
+
|
29
|
+
def valid_password?
|
30
|
+
password = get_auth[:password]
|
31
|
+
!(password.nil? || password == '')
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def get_auth
|
36
|
+
send(:default_options)[:basic_auth] || {}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.included(klass)
|
41
|
+
klass.extend ClassMethods
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Methods for finding resources
|
46
|
+
module FinderMethods
|
47
|
+
module ClassMethods
|
48
|
+
def all
|
49
|
+
res = get "/notes"
|
50
|
+
if send(:ok?, res)
|
51
|
+
res.parsed_response['notes'].map do |note|
|
52
|
+
send :build_from_hash, note
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def find(id)
|
58
|
+
res = get "/notes/#{id}"
|
59
|
+
if send(:ok?, res)
|
60
|
+
send :build_from_hash, res.parsed_response['notes'].first
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def first
|
65
|
+
all.first
|
66
|
+
end
|
67
|
+
|
68
|
+
def last
|
69
|
+
all.last
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.included(klass)
|
74
|
+
klass.extend ClassMethods
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
module CRUDMethods
|
79
|
+
|
80
|
+
module ClassMethods
|
81
|
+
private
|
82
|
+
def build_from_hash(hash)
|
83
|
+
send :new, hash
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.included(klass)
|
88
|
+
klass.extend ClassMethods
|
89
|
+
end
|
90
|
+
|
91
|
+
def initialize(attributes)
|
92
|
+
@attr = self.class.send :stringify_keys, attributes
|
93
|
+
@id = @attr['id']
|
94
|
+
@created_at = @attr['created_at']
|
95
|
+
@modified_at = @attr['modified_at']
|
96
|
+
@source = @attr['source']
|
97
|
+
@source_url = @attr['source_url']
|
98
|
+
@children = @attr['children']
|
99
|
+
@text = @attr['text']
|
100
|
+
@summary = @attr['summary']
|
101
|
+
@tags = @attr['tags']
|
102
|
+
@reminder_at = @attr['reminder_at']
|
103
|
+
@location = @attr['location']
|
104
|
+
unless @attr['user'].nil?
|
105
|
+
@user_name = @attr['user']['user_name']
|
106
|
+
@user_id = @attr['user']['id']
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def save!
|
111
|
+
res = if new_record?
|
112
|
+
self.class.send(:post, "/notes", :body => post_body)
|
113
|
+
else
|
114
|
+
self.class.send(:post, "/notes/#{self.id}", :body => post_body)
|
115
|
+
end
|
116
|
+
if self.class.send(:ok?, res)
|
117
|
+
rebuild res.parsed_response['notes'].first
|
118
|
+
end
|
119
|
+
true
|
120
|
+
end
|
121
|
+
|
122
|
+
def save
|
123
|
+
save!
|
124
|
+
rescue
|
125
|
+
false
|
126
|
+
end
|
127
|
+
|
128
|
+
def destroy!
|
129
|
+
raise CatchNotes::NotFound if new_record? # can't delete an unsaved note
|
130
|
+
res = self.class.send(:delete, "/notes/#{self.id}")
|
131
|
+
self.class.send(:ok?, res)
|
132
|
+
end
|
133
|
+
|
134
|
+
def destroy
|
135
|
+
destroy!
|
136
|
+
rescue
|
137
|
+
false
|
138
|
+
end
|
139
|
+
|
140
|
+
private
|
141
|
+
def post_body
|
142
|
+
{
|
143
|
+
'text' => send(:text)
|
144
|
+
}.map{|k,v| "#{URI.encode(k)}=#{URI.encode(v)}"}.join("&")
|
145
|
+
end
|
146
|
+
|
147
|
+
def rebuild(attrs)
|
148
|
+
initialize(attrs)
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
module Util
|
154
|
+
|
155
|
+
module ClassMethods
|
156
|
+
def stringify_keys (input_hash)
|
157
|
+
input_hash.map{|k,v| [k.to_s, v]}.inject({}) do |hash, pair|
|
158
|
+
hash[pair.first] = pair.last
|
159
|
+
hash
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
private
|
164
|
+
def ok?(response)
|
165
|
+
case response.code
|
166
|
+
when 200 then true
|
167
|
+
when 401 then raise CatchNotes::AuthError
|
168
|
+
when 404 then raise CatchNotes::NotFound
|
169
|
+
else raise CatchNotes::CatchNotesError
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def new_record?
|
175
|
+
i = self.send :id
|
176
|
+
i.nil?
|
177
|
+
end
|
178
|
+
|
179
|
+
def self.included(klass)
|
180
|
+
klass.extend ClassMethods
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
include AuthItems
|
186
|
+
include FinderMethods
|
187
|
+
include CRUDMethods
|
188
|
+
include Util
|
189
|
+
|
190
|
+
end
|
191
|
+
end
|
data/lib/catch_notes.rb
ADDED
data/test/faker.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'json'
|
3
|
+
module Faker
|
4
|
+
|
5
|
+
HOST = 'localhost'
|
6
|
+
PORT = 7000
|
7
|
+
|
8
|
+
class Server < Sinatra::Base
|
9
|
+
|
10
|
+
use Rack::Auth::Basic do |username, password|
|
11
|
+
[username, password] == ['foo@example.com', 'foobar']
|
12
|
+
end
|
13
|
+
|
14
|
+
helpers do
|
15
|
+
def build_note(opts = {})
|
16
|
+
opts = {
|
17
|
+
'id' => rand(332422),
|
18
|
+
'text' => "A Note for testing."
|
19
|
+
}.merge(opts)
|
20
|
+
{
|
21
|
+
"browser_url" => "https:\/\/catch.com\/m\/BPTEv\/6Jmd9SKkP0f",
|
22
|
+
"public_url" => nil,
|
23
|
+
"source" => "Catch.com",
|
24
|
+
"text" => opts['text'],
|
25
|
+
"created_at" => "2010-11-02T15:57:46.919Z",
|
26
|
+
"tags" => [],
|
27
|
+
"modified_at" => "2010-11-03T13:47:28.674Z",
|
28
|
+
"source_url" => "https:\/\/catch.com\/",
|
29
|
+
"children" => 0,
|
30
|
+
"reminder_at" => nil,
|
31
|
+
"location" => nil,
|
32
|
+
"summary" => opts['text'].lines.first,
|
33
|
+
"id" => opts['id'],
|
34
|
+
"user" => {
|
35
|
+
"user_name" => "joe_user",
|
36
|
+
"id" => 7923442
|
37
|
+
}
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# For getting all notes
|
43
|
+
get "/notes" do
|
44
|
+
content_type 'application/json', :charset => 'utf-8'
|
45
|
+
JSON.generate({
|
46
|
+
'notes' => [
|
47
|
+
build_note('text'=>'Test note one'),
|
48
|
+
build_note('text'=>'Test note two'),
|
49
|
+
build_note('text'=>'Test note three'),
|
50
|
+
build_note('text'=>'Test note four')
|
51
|
+
]
|
52
|
+
})
|
53
|
+
end
|
54
|
+
|
55
|
+
# For getting a note by id
|
56
|
+
get %r{/notes/(\d+)} do |id|
|
57
|
+
halt 404 if id.to_i == 13
|
58
|
+
content_type 'application/json', :charset => 'utf-8'
|
59
|
+
JSON.generate({
|
60
|
+
'notes' => [build_note('id'=> id.to_i)]
|
61
|
+
})
|
62
|
+
end
|
63
|
+
|
64
|
+
# For posting new notes
|
65
|
+
post "/notes" do
|
66
|
+
content_type 'application/json', :charset => 'utf-8'
|
67
|
+
JSON.generate({
|
68
|
+
'notes' => [
|
69
|
+
build_note('text' => params[:text])
|
70
|
+
]
|
71
|
+
})
|
72
|
+
end
|
73
|
+
|
74
|
+
# For posting updates to notes
|
75
|
+
post %r{/notes/(\d+)} do |id|
|
76
|
+
content_type 'application/json', :charset => 'utf-8'
|
77
|
+
JSON.generate({
|
78
|
+
'notes' => [
|
79
|
+
build_note('text' => params[:text], 'id' => params[:id].to_i)
|
80
|
+
]
|
81
|
+
})
|
82
|
+
end
|
83
|
+
|
84
|
+
# For deleting a note
|
85
|
+
delete %r{/notes/(\d+)} do |id|
|
86
|
+
halt 404 if id.to_i == 13
|
87
|
+
content_type 'application/json', :charset => 'utf-8'
|
88
|
+
"null"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
Thread.new do
|
93
|
+
Server.run! :host => HOST, :port => PORT.to_i
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'faker'
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
+
require 'catch_notes'
|
9
|
+
|
10
|
+
class Test::Unit::TestCase
|
11
|
+
|
12
|
+
end
|
data/test/note_class.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'catch_notes'
|
2
|
+
require 'faker'
|
3
|
+
class NoteClass < CatchNotes::Base
|
4
|
+
base_uri "http://#{Faker::HOST}:#{Faker::PORT}"
|
5
|
+
|
6
|
+
def self.good_user
|
7
|
+
username "foo@example.com"
|
8
|
+
password "foobar"
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.bad_user
|
12
|
+
username "bad@example.com"
|
13
|
+
password "foobad"
|
14
|
+
end
|
15
|
+
|
16
|
+
good_user
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'note_class'
|
3
|
+
|
4
|
+
class TestCatchNotes < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
NoteClass.good_user
|
8
|
+
end
|
9
|
+
|
10
|
+
should "have valid login info" do
|
11
|
+
assert_instance_of Class, NoteClass
|
12
|
+
assert NoteClass.valid_username?, "Need a username to connect"
|
13
|
+
assert NoteClass.valid_password?, "Need a password to connect"
|
14
|
+
end
|
15
|
+
|
16
|
+
should "be able to get all notes as an array of notes" do
|
17
|
+
notes = NoteClass.all
|
18
|
+
assert_instance_of Array, notes
|
19
|
+
assert_instance_of NoteClass, notes.first
|
20
|
+
end
|
21
|
+
|
22
|
+
should "be able to get the first note" do
|
23
|
+
assert_instance_of NoteClass, NoteClass.first
|
24
|
+
end
|
25
|
+
|
26
|
+
should "be able to get the last note" do
|
27
|
+
assert_instance_of NoteClass, NoteClass.last
|
28
|
+
end
|
29
|
+
|
30
|
+
should "be able to find a note by its id" do
|
31
|
+
note = NoteClass.find 42
|
32
|
+
assert_instance_of NoteClass, note
|
33
|
+
end
|
34
|
+
|
35
|
+
should "be able to create and save a new note" do
|
36
|
+
text = 'This is a new note.'
|
37
|
+
note = NoteClass.new :text=> text
|
38
|
+
assert note.new_record?
|
39
|
+
assert note.save
|
40
|
+
assert !note.new_record?
|
41
|
+
assert_equal text, note.text
|
42
|
+
end
|
43
|
+
|
44
|
+
should "be able to update an existing note" do
|
45
|
+
note = NoteClass.first
|
46
|
+
note.text= "This is the new text"
|
47
|
+
assert note.save
|
48
|
+
end
|
49
|
+
|
50
|
+
should "be able to delete a note" do
|
51
|
+
note = NoteClass.first
|
52
|
+
assert_nothing_raised do
|
53
|
+
note.destroy!
|
54
|
+
end
|
55
|
+
assert note.destroy
|
56
|
+
end
|
57
|
+
|
58
|
+
should "not be able to delete a new note" do
|
59
|
+
note = NoteClass.new :text => "Hello World"
|
60
|
+
assert !note.destroy
|
61
|
+
end
|
62
|
+
|
63
|
+
should "raise a NotFound error when a note doesn't exist" do
|
64
|
+
assert_raise CatchNotes::NotFound do
|
65
|
+
NoteClass.find 13
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
should "not be able to access listing with bad username and password" do
|
70
|
+
NoteClass.bad_user
|
71
|
+
assert_raise CatchNotes::AuthError do
|
72
|
+
NoteClass.all
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
should "not allow a bad user to create a note" do
|
77
|
+
NoteClass.bad_user
|
78
|
+
assert_raise CatchNotes::AuthError do
|
79
|
+
NoteClass.new(:text=>"Bad note").save!
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
should "not allow a bad user to delete a note" do
|
84
|
+
note = NoteClass.first
|
85
|
+
NoteClass.bad_user
|
86
|
+
assert_raise CatchNotes::AuthError do
|
87
|
+
note.destroy!
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: CatchNotes_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Wade West
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-05 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: httparty
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 5
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 6
|
33
|
+
- 1
|
34
|
+
version: 0.6.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: json
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 11
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 4
|
49
|
+
- 6
|
50
|
+
version: 1.4.6
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: thoughtbot-shoulda
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
type: :development
|
66
|
+
version_requirements: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: sinatra
|
69
|
+
prerelease: false
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 19
|
76
|
+
segments:
|
77
|
+
- 1
|
78
|
+
- 1
|
79
|
+
- 0
|
80
|
+
version: 1.1.0
|
81
|
+
type: :development
|
82
|
+
version_requirements: *id004
|
83
|
+
description: An ActiveResource like interface to catch.com
|
84
|
+
email: wwest81@gmail.com
|
85
|
+
executables: []
|
86
|
+
|
87
|
+
extensions: []
|
88
|
+
|
89
|
+
extra_rdoc_files:
|
90
|
+
- LICENSE
|
91
|
+
- README.rdoc
|
92
|
+
files:
|
93
|
+
- .document
|
94
|
+
- .gitignore
|
95
|
+
- CatchNotes_api.gemspec
|
96
|
+
- LICENSE
|
97
|
+
- README.rdoc
|
98
|
+
- Rakefile
|
99
|
+
- VERSION
|
100
|
+
- lib/catch_notes.rb
|
101
|
+
- lib/catch_notes/base.rb
|
102
|
+
- lib/catch_notes/errors.rb
|
103
|
+
- test/faker.rb
|
104
|
+
- test/helper.rb
|
105
|
+
- test/note_class.rb
|
106
|
+
- test/test_catch_notes.rb
|
107
|
+
has_rdoc: true
|
108
|
+
homepage: http://github.com/wadewest/CatchNotes_api
|
109
|
+
licenses: []
|
110
|
+
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options:
|
113
|
+
- --charset=UTF-8
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
hash: 3
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
hash: 3
|
131
|
+
segments:
|
132
|
+
- 0
|
133
|
+
version: "0"
|
134
|
+
requirements: []
|
135
|
+
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 1.3.7
|
138
|
+
signing_key:
|
139
|
+
specification_version: 3
|
140
|
+
summary: An ActiveResource like interface to catch.com
|
141
|
+
test_files:
|
142
|
+
- test/faker.rb
|
143
|
+
- test/helper.rb
|
144
|
+
- test/note_class.rb
|
145
|
+
- test/test_catch_notes.rb
|