simonjefford-simplenote 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.autotest ADDED
@@ -0,0 +1,6 @@
1
+ Autotest.add_hook :initialize do |at|
2
+ at.clear_mappings
3
+
4
+ at.add_mapping(%r{^test/.*_test\.rb$}) {|f, _| [f] }
5
+ at.add_mapping(%r{^lib/(.*)\.rb$}) {|_, m| ["test/#{m[1]}_test.rb"]}
6
+ end
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Simon Jefford
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,17 @@
1
+ = simplenote
2
+
3
+ A dead simple gem for accessing SimpleNote notes via its API
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (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)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2009 Simon Jefford. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,61 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "simplenote"
8
+ gem.summary = %Q{Simple wrapper for the SimpleNote HTTP API}
9
+ gem.description = %Q{Uses HTTParty to present a nice Ruby wrapper for SimpleNote}
10
+ gem.email = "simon.jefford@gmail.com"
11
+ gem.homepage = "http://github.com/simonjefford/simplenote"
12
+ gem.authors = ["Simon Jefford"]
13
+ gem.add_development_dependency "thoughtbot-shoulda"
14
+ gem.add_development_dependency "crack"
15
+ gem.add_development_dependency "jnunemaker-matchy"
16
+ gem.add_development_dependency "jferris-mocha", "=0.9.5.0.1241126838"
17
+ gem.add_runtime_dependency "httparty"
18
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
+ end
20
+ Jeweler::GemcutterTasks.new
21
+ rescue LoadError
22
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
23
+ end
24
+
25
+ require 'rake/testtask'
26
+ Rake::TestTask.new(:test) do |test|
27
+ test.libs << 'test'
28
+ test.pattern = 'test/**/*_test.rb'
29
+ test.verbose = true
30
+ end
31
+
32
+ begin
33
+ require 'rcov/rcovtask'
34
+ Rcov::RcovTask.new do |test|
35
+ test.libs << 'test'
36
+ test.pattern = 'test/**/*_test.rb'
37
+ test.verbose = true
38
+ end
39
+ rescue LoadError
40
+ task :rcov do
41
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
42
+ end
43
+ end
44
+
45
+ task :test => :check_dependencies
46
+
47
+ task :default => :test
48
+
49
+ require 'rake/rdoctask'
50
+ Rake::RDocTask.new do |rdoc|
51
+ if File.exist?('VERSION')
52
+ version = File.read('VERSION')
53
+ else
54
+ version = ""
55
+ end
56
+
57
+ rdoc.rdoc_dir = 'rdoc'
58
+ rdoc.title = "simplenote #{version}"
59
+ rdoc.rdoc_files.include('README*')
60
+ rdoc.rdoc_files.include('lib/**/*.rb')
61
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/simplenote.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'httparty'
2
+ require 'base64'
3
+ require 'crack'
4
+
5
+ class SimpleNote
6
+ include HTTParty
7
+ attr_reader :token, :email
8
+ base_uri 'https://simple-note.appspot.com/api'
9
+
10
+ def login(email, password)
11
+ encoded_body = Base64.encode64({:email => email, :password => password}.to_params)
12
+ @email = email
13
+ @token = self.class.post "/login", :body => encoded_body
14
+ end
15
+
16
+ def get_index
17
+ self.class.get "/index", :query => { :auth => token, :email => email }, :format => :json
18
+ end
19
+
20
+ def get_note(key)
21
+ self.class.get "/note", :query => { :key => key, :auth => token, :email => email }
22
+ end
23
+ end
@@ -0,0 +1,52 @@
1
+ require 'test_helper'
2
+
3
+ class SimpleNoteTest < Test::Unit::TestCase
4
+ context "login" do
5
+ setup do
6
+ SimpleNote.stubs(:post).returns("token")
7
+ @simplenote = SimpleNote.new
8
+ @email = "validaccount@example.com"
9
+ @password = "correctpassword"
10
+ @simplenote.login(@email, @password)
11
+ end
12
+
13
+ should "store the returned token" do
14
+ @simplenote.token.should == "token"
15
+ end
16
+
17
+ should "store the email" do
18
+ @simplenote.email.should == @email
19
+ end
20
+
21
+ should "post to /login with email and password base 64 encoded" do
22
+ expected_body = Base64.encode64({ :email => @email, :password => @password}.to_params)
23
+ assert_received(SimpleNote, :post) do |expect|
24
+ expect.with "/login", :body => expected_body
25
+ end
26
+ end
27
+ end
28
+
29
+ context "get_index" do
30
+ setup do
31
+ # TODO - test helper to construct urls given a SimpleNote object
32
+ @url = "https://simple-note.appspot.com/api/index?email=me%40example.com&auth=token"
33
+ body = '[{"key":"notekey", "modify":"2009-09-02 12:00:00.000000", "key":"AB1234"}]'
34
+ FakeWeb.register_uri(:get, @url, :body => body)
35
+ @simplenote = SimpleNote.new
36
+ @simplenote.stubs(:token).returns("token")
37
+ @simplenote.stubs(:email).returns("me@example.com")
38
+ @index = @simplenote.get_index
39
+ end
40
+
41
+ should "return an Array" do
42
+ @index.should be_kind_of(Array)
43
+ end
44
+
45
+ context "returned array" do
46
+ should "contain a single Hash" do
47
+ @index.length.should == 1
48
+ @index[0].should be_kind_of(Hash)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'simplenote'
8
+ %w(httparty matchy fakeweb mocha base64 crack).each { |x| require x }
9
+ FakeWeb.allow_net_connect = false
10
+
11
+ class Test::Unit::TestCase
12
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simonjefford-simplenote
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Simon Jefford
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-03 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: crack
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: jnunemaker-matchy
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: jferris-mocha
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "="
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.5.0.1241126838
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ type: :runtime
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ description: Uses HTTParty to present a nice Ruby wrapper for SimpleNote
66
+ email: simon.jefford@gmail.com
67
+ executables: []
68
+
69
+ extensions: []
70
+
71
+ extra_rdoc_files:
72
+ - LICENSE
73
+ - README.rdoc
74
+ files:
75
+ - .autotest
76
+ - .document
77
+ - .gitignore
78
+ - LICENSE
79
+ - README.rdoc
80
+ - Rakefile
81
+ - VERSION
82
+ - lib/simplenote.rb
83
+ - test/simplenote_test.rb
84
+ - test/test_helper.rb
85
+ has_rdoc: false
86
+ homepage: http://github.com/simonjefford/simplenote
87
+ post_install_message:
88
+ rdoc_options:
89
+ - --charset=UTF-8
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: "0"
97
+ version:
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: "0"
103
+ version:
104
+ requirements: []
105
+
106
+ rubyforge_project:
107
+ rubygems_version: 1.2.0
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Simple wrapper for the SimpleNote HTTP API
111
+ test_files:
112
+ - test/simplenote_test.rb
113
+ - test/test_helper.rb