CatchNotes_api 0.1.2 → 0.1.3
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/CHANGELOG.rdoc +11 -0
- data/CatchNotes_api.gemspec +9 -5
- data/README.rdoc +19 -5
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/catch_notes/base.rb +53 -41
- data/lib/catch_notes/tagging.rb +19 -0
- data/lib/catch_notes.rb +30 -3
- data/test/faker.rb +35 -2
- data/test/test_catch_notes.rb +7 -2
- data/test/test_tagging.rb +25 -0
- metadata +9 -5
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
== v0.1.3
|
2
|
+
* Added tag listing support.
|
3
|
+
* Added searching by tag.
|
4
|
+
== v0.1.2
|
5
|
+
* Added support for updating a note.
|
6
|
+
* Added support for deleting a note.
|
7
|
+
== v0.1.1
|
8
|
+
* Added support for creating a new note.
|
9
|
+
== v0.1.0
|
10
|
+
* Added support for listing all notes.
|
11
|
+
* Added support for finding a single note by its id.
|
data/CatchNotes_api.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{CatchNotes_api}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Wade West"]
|
12
|
-
s.date = %q{2010-11-
|
12
|
+
s.date = %q{2010-11-08}
|
13
13
|
s.description = %q{An ActiveResource like interface to catch.com}
|
14
14
|
s.email = %q{wwest81@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".gitignore",
|
22
|
+
"CHANGELOG.rdoc",
|
22
23
|
"CatchNotes_api.gemspec",
|
23
24
|
"LICENSE",
|
24
25
|
"README.rdoc",
|
@@ -27,10 +28,12 @@ Gem::Specification.new do |s|
|
|
27
28
|
"lib/catch_notes.rb",
|
28
29
|
"lib/catch_notes/base.rb",
|
29
30
|
"lib/catch_notes/errors.rb",
|
31
|
+
"lib/catch_notes/tagging.rb",
|
30
32
|
"test/faker.rb",
|
31
33
|
"test/helper.rb",
|
32
34
|
"test/note_class.rb",
|
33
|
-
"test/test_catch_notes.rb"
|
35
|
+
"test/test_catch_notes.rb",
|
36
|
+
"test/test_tagging.rb"
|
34
37
|
]
|
35
38
|
s.homepage = %q{http://github.com/wadewest/CatchNotes_api}
|
36
39
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -41,7 +44,8 @@ Gem::Specification.new do |s|
|
|
41
44
|
"test/faker.rb",
|
42
45
|
"test/helper.rb",
|
43
46
|
"test/note_class.rb",
|
44
|
-
"test/test_catch_notes.rb"
|
47
|
+
"test/test_catch_notes.rb",
|
48
|
+
"test/test_tagging.rb"
|
45
49
|
]
|
46
50
|
|
47
51
|
if s.respond_to? :specification_version then
|
@@ -50,7 +54,7 @@ Gem::Specification.new do |s|
|
|
50
54
|
|
51
55
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
56
|
s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
|
53
|
-
s.
|
57
|
+
s.add_development_dependency(%q<json>, [">= 1.4.6"])
|
54
58
|
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
55
59
|
s.add_development_dependency(%q<sinatra>, [">= 1.1.0"])
|
56
60
|
else
|
data/README.rdoc
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
= CatchNotes_api
|
2
2
|
|
3
3
|
== Usage
|
4
|
+
# requiring
|
5
|
+
require 'catch_notes'
|
4
6
|
|
5
7
|
# setting up your note class
|
6
8
|
class Note < CatchNotes::Base
|
@@ -16,15 +18,27 @@
|
|
16
18
|
first.text # the text content of the note
|
17
19
|
|
18
20
|
# creating notes
|
19
|
-
|
20
|
-
|
21
|
+
my_note = Note.new :text => "My New Note"
|
22
|
+
my_note.save # will return true if all is good
|
21
23
|
|
22
24
|
# updating a note
|
23
|
-
|
24
|
-
|
25
|
+
my_note.text = "My Updated Note"
|
26
|
+
my_note.save
|
25
27
|
|
26
28
|
# deleting a note
|
27
|
-
|
29
|
+
my_note.destroy # will return true if all is good
|
30
|
+
|
31
|
+
# listing tags
|
32
|
+
Note.tags
|
33
|
+
|
34
|
+
# finding note by a tag
|
35
|
+
my_notes = Note.find_all_by_tag 'blah'
|
36
|
+
|
37
|
+
my_note = Note.find_by_tag 'blah'
|
38
|
+
|
39
|
+
== Todo
|
40
|
+
|
41
|
+
* Add CRUD support for image attachments.
|
28
42
|
|
29
43
|
== Note on Patches/Pull Requests
|
30
44
|
|
data/Rakefile
CHANGED
@@ -12,8 +12,8 @@ begin
|
|
12
12
|
gem.authors = ["Wade West"]
|
13
13
|
|
14
14
|
gem.add_dependency 'httparty', '>=0.6.1'
|
15
|
-
gem.add_dependency 'json', '>=1.4.6'
|
16
15
|
|
16
|
+
gem.add_development_dependency 'json', '>=1.4.6'
|
17
17
|
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
18
18
|
gem.add_development_dependency "sinatra", ">= 1.1.0"
|
19
19
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/catch_notes/base.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'httparty'
|
2
|
-
require 'json'
|
3
2
|
module CatchNotes
|
4
3
|
class Base
|
5
4
|
|
@@ -47,18 +46,39 @@ module CatchNotes
|
|
47
46
|
module ClassMethods
|
48
47
|
def all
|
49
48
|
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
|
49
|
+
build_note_array( res.parsed_response['notes'] ) if send(:ok?, res)
|
55
50
|
end
|
56
51
|
|
57
|
-
def find(id)
|
52
|
+
def find!(id)
|
58
53
|
res = get "/notes/#{id}"
|
59
|
-
if send(:ok?,
|
60
|
-
|
61
|
-
|
54
|
+
send(:build_from_hash,res.parsed_response['notes'].first ) if send(:ok?,res)
|
55
|
+
end
|
56
|
+
|
57
|
+
def find(id)
|
58
|
+
find!(id)
|
59
|
+
rescue CatchNotes::NotFound
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def find_all_by_tag!( tag_name )
|
64
|
+
res = get "/search?q=%23#{tag_name}"
|
65
|
+
build_note_array( res.parsed_response['notes'] ) if send(:ok?, res)
|
66
|
+
end
|
67
|
+
|
68
|
+
def find_all_by_tag( tag_name )
|
69
|
+
find_all_by_tag!(tag_name)
|
70
|
+
rescue
|
71
|
+
[]
|
72
|
+
end
|
73
|
+
|
74
|
+
def find_by_tag!( tag_name )
|
75
|
+
find_all_by_tag!(tag_name).first
|
76
|
+
end
|
77
|
+
|
78
|
+
def find_by_tag( tag_name )
|
79
|
+
find_all_by_tag!(tag_name).first
|
80
|
+
rescue
|
81
|
+
nil
|
62
82
|
end
|
63
83
|
|
64
84
|
def first
|
@@ -68,6 +88,24 @@ module CatchNotes
|
|
68
88
|
def last
|
69
89
|
all.last
|
70
90
|
end
|
91
|
+
|
92
|
+
def tags
|
93
|
+
res = get "/tags"
|
94
|
+
if send(:ok?, res)
|
95
|
+
res.parsed_response['tags'].inject({}) do |hash, t|
|
96
|
+
hash[t['name']] = Tagging.new t, self
|
97
|
+
#hash[t['name'].to_sym] = Tagging.new t, self
|
98
|
+
hash
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
def build_note_array( notes )
|
105
|
+
notes.map do |note|
|
106
|
+
send :build_from_hash, note
|
107
|
+
end
|
108
|
+
end
|
71
109
|
end
|
72
110
|
|
73
111
|
def self.included(klass)
|
@@ -137,6 +175,11 @@ module CatchNotes
|
|
137
175
|
false
|
138
176
|
end
|
139
177
|
|
178
|
+
def new_record?
|
179
|
+
i = self.send :id
|
180
|
+
i.nil?
|
181
|
+
end
|
182
|
+
|
140
183
|
private
|
141
184
|
def post_body
|
142
185
|
{
|
@@ -147,39 +190,8 @@ module CatchNotes
|
|
147
190
|
def rebuild(attrs)
|
148
191
|
initialize(attrs)
|
149
192
|
end
|
150
|
-
|
151
|
-
end
|
152
193
|
|
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
194
|
|
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
195
|
end
|
184
196
|
|
185
197
|
include AuthItems
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
module CatchNotes
|
3
|
+
class Tagging
|
4
|
+
|
5
|
+
def initialize( attrs, creator )
|
6
|
+
@attrs = attrs
|
7
|
+
@creator = creator
|
8
|
+
end
|
9
|
+
|
10
|
+
def count
|
11
|
+
@attrs['count']
|
12
|
+
end
|
13
|
+
|
14
|
+
def notes
|
15
|
+
@creator.find_all_by_tag(@attr['name'])
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/catch_notes.rb
CHANGED
@@ -1,5 +1,32 @@
|
|
1
|
-
require 'catch_notes/errors'
|
2
|
-
require 'catch_notes/base'
|
3
1
|
module CatchNotes
|
4
|
-
|
2
|
+
module Util
|
3
|
+
|
4
|
+
module ClassMethods
|
5
|
+
def stringify_keys (input_hash)
|
6
|
+
input_hash.map{|k,v| [k.to_s, v]}.inject({}) do |hash, pair|
|
7
|
+
hash[pair.first] = pair.last
|
8
|
+
hash
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def ok?(response)
|
14
|
+
case response.code
|
15
|
+
when 200 then true
|
16
|
+
when 401 then raise CatchNotes::AuthError
|
17
|
+
when 404 then raise CatchNotes::NotFound
|
18
|
+
else raise CatchNotes::CatchNotesError
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.included(klass)
|
24
|
+
klass.extend ClassMethods
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
5
28
|
end
|
29
|
+
|
30
|
+
require 'catch_notes/errors'
|
31
|
+
require 'catch_notes/base'
|
32
|
+
require 'catch_notes/tagging'
|
data/test/faker.rb
CHANGED
@@ -15,7 +15,8 @@ module Faker
|
|
15
15
|
def build_note(opts = {})
|
16
16
|
opts = {
|
17
17
|
'id' => rand(332422),
|
18
|
-
'text' => "A Note for testing."
|
18
|
+
'text' => "A Note for testing.",
|
19
|
+
'tags' => []
|
19
20
|
}.merge(opts)
|
20
21
|
{
|
21
22
|
"browser_url" => "https:\/\/catch.com\/m\/BPTEv\/6Jmd9SKkP0f",
|
@@ -23,7 +24,7 @@ module Faker
|
|
23
24
|
"source" => "Catch.com",
|
24
25
|
"text" => opts['text'],
|
25
26
|
"created_at" => "2010-11-02T15:57:46.919Z",
|
26
|
-
"tags" => [],
|
27
|
+
"tags" => opts['tags'],
|
27
28
|
"modified_at" => "2010-11-03T13:47:28.674Z",
|
28
29
|
"source_url" => "https:\/\/catch.com\/",
|
29
30
|
"children" => 0,
|
@@ -87,6 +88,38 @@ module Faker
|
|
87
88
|
content_type 'application/json', :charset => 'utf-8'
|
88
89
|
"null"
|
89
90
|
end
|
91
|
+
|
92
|
+
# For listing tags
|
93
|
+
get "/tags" do
|
94
|
+
content_type 'application/json', :charset => 'utf-8'
|
95
|
+
JSON.generate({
|
96
|
+
'tags' => [
|
97
|
+
{ 'count' => 3,
|
98
|
+
'modified' => "2010-11-08T17:29:04.278Z",
|
99
|
+
'name' => 'blah'},
|
100
|
+
{ 'count' => 1,
|
101
|
+
'modified' => "2010-11-08T17:29:04.278Z",
|
102
|
+
'name' => 'foo'},
|
103
|
+
{ 'count' => 4,
|
104
|
+
'modified' => "2010-11-08T17:29:04.278Z",
|
105
|
+
'name' => 'bar'},
|
106
|
+
]
|
107
|
+
})
|
108
|
+
end
|
109
|
+
|
110
|
+
# For searching a tag
|
111
|
+
get '/search' do
|
112
|
+
content_type 'application/json', :charset => 'utf-8'
|
113
|
+
tag = params[:q].gsub(/^#/, '')
|
114
|
+
JSON.generate({
|
115
|
+
'notes' => [
|
116
|
+
build_note('text'=>'Test note one', 'tags' => [tag]),
|
117
|
+
build_note('text'=>'Test note two', 'tags' => [tag]),
|
118
|
+
build_note('text'=>'Test note three', 'tags' => [tag]),
|
119
|
+
build_note('text'=>'Test note four', 'tags' => [tag])
|
120
|
+
]
|
121
|
+
})
|
122
|
+
end
|
90
123
|
end
|
91
124
|
|
92
125
|
Thread.new do
|
data/test/test_catch_notes.rb
CHANGED
@@ -60,9 +60,14 @@ class TestCatchNotes < Test::Unit::TestCase
|
|
60
60
|
assert !note.destroy
|
61
61
|
end
|
62
62
|
|
63
|
-
should "raise a
|
63
|
+
should "raise a nil error when a note doesn't exist: find" do
|
64
|
+
assert_nil NoteClass.find 13
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
should "raise a NotFound error when a note doesn't exist: find!" do
|
64
69
|
assert_raise CatchNotes::NotFound do
|
65
|
-
NoteClass.find 13
|
70
|
+
NoteClass.find! 13
|
66
71
|
end
|
67
72
|
end
|
68
73
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'note_class'
|
3
|
+
|
4
|
+
class TestTagging < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
NoteClass.good_user
|
7
|
+
end
|
8
|
+
|
9
|
+
should "be able to get a list of tags" do
|
10
|
+
assert_instance_of Hash, NoteClass.tags
|
11
|
+
end
|
12
|
+
|
13
|
+
should "be able to find all notes with a given tag" do
|
14
|
+
notes = NoteClass.find_all_by_tag 'blah'
|
15
|
+
assert_instance_of Array, notes
|
16
|
+
assert_instance_of NoteClass, notes.first
|
17
|
+
assert_equal 'blah', notes.first.tags.first
|
18
|
+
end
|
19
|
+
|
20
|
+
should "be able to find the first note with a given tag" do
|
21
|
+
note = NoteClass.find_by_tag 'blah'
|
22
|
+
assert_instance_of NoteClass, note
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: CatchNotes_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Wade West
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-08 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -48,7 +48,7 @@ dependencies:
|
|
48
48
|
- 4
|
49
49
|
- 6
|
50
50
|
version: 1.4.6
|
51
|
-
type: :
|
51
|
+
type: :development
|
52
52
|
version_requirements: *id002
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: thoughtbot-shoulda
|
@@ -92,6 +92,7 @@ extra_rdoc_files:
|
|
92
92
|
files:
|
93
93
|
- .document
|
94
94
|
- .gitignore
|
95
|
+
- CHANGELOG.rdoc
|
95
96
|
- CatchNotes_api.gemspec
|
96
97
|
- LICENSE
|
97
98
|
- README.rdoc
|
@@ -100,10 +101,12 @@ files:
|
|
100
101
|
- lib/catch_notes.rb
|
101
102
|
- lib/catch_notes/base.rb
|
102
103
|
- lib/catch_notes/errors.rb
|
104
|
+
- lib/catch_notes/tagging.rb
|
103
105
|
- test/faker.rb
|
104
106
|
- test/helper.rb
|
105
107
|
- test/note_class.rb
|
106
108
|
- test/test_catch_notes.rb
|
109
|
+
- test/test_tagging.rb
|
107
110
|
has_rdoc: true
|
108
111
|
homepage: http://github.com/wadewest/CatchNotes_api
|
109
112
|
licenses: []
|
@@ -143,3 +146,4 @@ test_files:
|
|
143
146
|
- test/helper.rb
|
144
147
|
- test/note_class.rb
|
145
148
|
- test/test_catch_notes.rb
|
149
|
+
- test/test_tagging.rb
|