catch 0.0.1

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
+ .irbrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :gemcutter
2
+
3
+ # Specify your gem's dependencies in catch.gemspec
4
+ gemspec
@@ -0,0 +1,15 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ catch (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ bundler (>= 1.0.0)
15
+ catch!
@@ -0,0 +1,61 @@
1
+ # Catch
2
+
3
+ Ruby wrapper for the [Catch API](http://developer.catch.com).
4
+
5
+ ## Installation
6
+
7
+ sudo gem install catch
8
+
9
+ ## Usage
10
+
11
+ ### Instantiate a client (Basic Auth)
12
+
13
+ catch = Catch::Client.new(:username => "fooman", :password => "supersecrete")
14
+
15
+ ### or configure once
16
+
17
+ Catch.configure do |config|
18
+ config.username = "fooman"
19
+ config.password = "supersecret"
20
+ end
21
+ catch = Catch::Client.new
22
+
23
+ #### Examples
24
+
25
+ catch.notes
26
+ catch.note(<note_id>)
27
+ catch.add_note({:text => "Lorem ipsum dolor"})
28
+ catch.modify_note(<note_id>, {:text => "Lorem ipsum dolor"})
29
+ catch.delete_note(<note_id>)
30
+
31
+ catch.comments(<note_id>)
32
+ catch.comment(<note_id>, <comment_id>)
33
+ catch.add_comment(<note_id>, {:text => "Lorem ipsum dolor"})
34
+ catch.modify_comment(<note_id>, <comment_id>, {:text => "Lorem ipsum dolor"})
35
+ catch.delete_comment(<note_id>, <comment_id>)
36
+
37
+ catch.add_media(<note_id>, <filepath>)
38
+ catch.media(<note_id>, <media_id>)
39
+ catch.delete_media(<note_id>, <media_id>)
40
+
41
+ catch.search(<query string>)
42
+
43
+ catch.user
44
+
45
+ catch.tags
46
+
47
+ ## Note on Patches/Pull Requests
48
+
49
+ * Fork the project.
50
+ * Make your feature addition or bug fix.
51
+ * Add tests for it. This is important so I don't break it in a
52
+ future version unintentionally.
53
+ * Commit, do not mess with rakefile, version, or history.
54
+ (if you want to have your own version, that is fine but
55
+ bump version in a commit by itself I can ignore when I pull)
56
+ * Send me a pull request. Bonus points for topic branches.
57
+
58
+ ## Copyright
59
+
60
+ Copyright (c) 2011 Samuel Mullen. See LICENSE for details.
61
+
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/catch/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "catch"
6
+ s.version = Catch::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Samuel Mullen"]
9
+ s.email = ["samullen@gmail.com"]
10
+ s.homepage = "http://rubygems.org/gems/catch"
11
+ s.summary = "Ruby wrapper for Catch.com's API"
12
+ s.description = "Ruby wrapper for Catch.com's API"
13
+
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+ s.rubyforge_project = "catch"
16
+
17
+ s.add_dependency('hashie', '>= 1.0.0')
18
+ s.add_dependency('faraday', '>= 0.6.1')
19
+ s.add_dependency('faraday_middleware', '>= 0.6.3')
20
+
21
+ s.add_development_dependency "bundler", ">= 1.0.0"
22
+ s.add_development_dependency('fakeweb', '>= 1.3.0')
23
+
24
+ s.files = `git ls-files`.split("\n")
25
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
26
+ s.require_path = 'lib'
27
+ end
@@ -0,0 +1,24 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+
6
+ module Catch
7
+ class << self
8
+ attr_accessor :username
9
+ attr_accessor :password
10
+
11
+ def configure
12
+ yield self
13
+ true
14
+ end
15
+ end
16
+
17
+ require 'catch/comment'
18
+ require 'catch/media'
19
+ require 'catch/note'
20
+ require 'catch/search'
21
+ require 'catch/tag'
22
+ require 'catch/user'
23
+ require 'catch/client'
24
+ end
@@ -0,0 +1,48 @@
1
+ module Catch
2
+ class Client
3
+ include Comment
4
+ include Media
5
+ include Note
6
+ include Search
7
+ include Tag
8
+ include User
9
+
10
+ attr_reader :api_url, :username
11
+
12
+ def initialize(options={})
13
+ @api_url = "https://api.catch.com/v2"
14
+ @username = options[:username] || Catch.username
15
+ password = options[:password] || Catch.password
16
+ connection.basic_auth(@username, password)
17
+ media_connection.basic_auth(@username, password)
18
+ end
19
+
20
+ def connection
21
+ @connection ||= Faraday.new(:url => @api_url, :headers => default_headers) do |builder|
22
+ builder.request :multipart
23
+ builder.request :url_encoded
24
+ builder.request :json
25
+ builder.adapter Faraday.default_adapter
26
+ builder.use Faraday::Response::Mashify
27
+ builder.use Faraday::Response::ParseJson
28
+ end
29
+ end
30
+
31
+ def media_connection
32
+ @media_connection ||= Faraday.new(:url => @api_url, :headers => default_headers) do |builder|
33
+ builder.request :multipart
34
+ builder.request :url_encoded
35
+ builder.adapter Faraday.default_adapter
36
+ builder.use Faraday::Response::Mashify
37
+ end
38
+ end
39
+ private
40
+
41
+ def default_headers
42
+ headers = {
43
+ :accept => 'application/json',
44
+ :user_agent => 'Ruby gem'
45
+ }
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,38 @@
1
+ module Catch
2
+ module Comment
3
+ def comments(note_id, params={})
4
+ connection.get do |req|
5
+ req.url("comments/#{note_id}")
6
+ req.params.merge!(params)
7
+ end.body.notes
8
+ end
9
+
10
+ def comment(note_id, comment_id)
11
+ params = {:comment => comment_id}
12
+ connection.get do |req|
13
+ req.url("comment/#{note_id}")
14
+ req.params.merge!(params)
15
+ end.body.notes.first
16
+ end
17
+
18
+ def add_comment(note_id, params={})
19
+ payload = params.map {|k,v| "#{k}=#{v}"}.join("&")
20
+ response = connection.post "comments/#{note_id}", payload
21
+ response.body.notes.first
22
+ end
23
+
24
+ def modify_comment(note_id, comment_id, params={})
25
+ payload = {:comment => comment_id }
26
+ payload.merge! params
27
+
28
+ response = connection.post do |req|
29
+ req.url("comments/#{note_id}")
30
+ req.params.merge!(payload)
31
+ end.body.notes.first
32
+ end
33
+
34
+ def delete_comment(note_id, comment_id)
35
+ connection.delete("comments/#{note_id}?comment=#{comment_id}").body.status == 'ok'
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,28 @@
1
+ module Catch
2
+ module Media
3
+
4
+ def add_media(id, filepath, params={})
5
+ params.merge!({:data => Faraday::UploadIO.new(filepath, 'image/jpeg')})
6
+
7
+ connection.put("media/#{id}", params).body
8
+ end
9
+
10
+ def media(note_id, media_id, params={})
11
+ media_connection.get do |req|
12
+ req.url("media/#{note_id}/#{media_id}")
13
+ req.params.merge!(params)
14
+ end.body
15
+ end
16
+
17
+ def delete_media(note_id, media_id)
18
+ connection.delete("media/#{note_id}/#{media_id}").body.status == 'ok'
19
+ end
20
+
21
+ # def shared_media(note_id, media_id, params={})
22
+ # media_connection.get do |req|
23
+ # req.url("media/#{note_id}/#{media_id}")
24
+ # req.params.merge!(params)
25
+ # end.body
26
+ # end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ module Catch
2
+ module Note
3
+ def notes(params={})
4
+ connection.get do |req|
5
+ req.url("notes")
6
+ req.params.merge!(params)
7
+ end.body.notes
8
+ end
9
+
10
+ def note(id)
11
+ connection.get("notes/#{id}").body.notes.first
12
+ end
13
+
14
+ def add_note(params={})
15
+ payload = params.map {|k,v| "#{k}=#{v}"}.join("&")
16
+ response = connection.post "notes", payload
17
+ response.body.notes.first
18
+ end
19
+
20
+ def modify_note(id, params={})
21
+ payload = params.map {|k,v| "#{k}=#{v}"}.join("&")
22
+ response = connection.post "notes/#{id}", payload
23
+ response.body.notes.first
24
+ end
25
+
26
+ def delete_note(id)
27
+ connection.delete("notes/#{id}").body.status == 'ok'
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ module Catch
2
+ module Search
3
+ def search(query, params={})
4
+ params[:q] = query
5
+
6
+ connection.get do |req|
7
+ req.url("search")
8
+ # req.params = params
9
+ req.params.merge!(params)
10
+ end.body.notes
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module Catch
2
+ module Tag
3
+ def tags
4
+ connection.get("tags").body.tags
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Catch
2
+ module User
3
+ def user
4
+ connection.get("user").body.user
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Catch
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,30 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'helper'
5
+
6
+ describe Catch::Client do
7
+ before do
8
+ @client = catch_test_client
9
+ end
10
+
11
+ describe "accessing the API" do
12
+ it "sets the default url" do
13
+ client = Catch::Client.new
14
+ client.api_url.must_equal 'https://api.catch.com/v2'
15
+ end
16
+ end
17
+
18
+ describe "Configuring some defaults" do
19
+ it "sets username and and api_url" do
20
+ Catch.configure do |config|
21
+ config.username = "barman"
22
+ config.password = "321321321"
23
+ end
24
+
25
+ client = Catch::Client.new
26
+ client.username.must_equal "barman"
27
+ client.api_url.must_equal "https://api.catch.com/v2"
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,89 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'helper'
5
+
6
+ describe Catch::Comment do
7
+ before do
8
+ @client = catch_test_client
9
+ end
10
+
11
+ describe "#comments" do
12
+ before do
13
+ @comments_url = "https://fooman:123123123@api.catch.com/v2/comments/123"
14
+ stub_get(@comments_url, "comments.json")
15
+ @comments = @client.comments(123)
16
+ end
17
+
18
+ it "retrieves a list of comments for a specified note as an array" do
19
+ @comments.must_be_instance_of Array
20
+ end
21
+
22
+ it "retrieves values from a comment within the retrieved array" do
23
+ @comments.first.text.must_equal "Lorem ipsum dolor1"
24
+ end
25
+
26
+ it "takes a hash as a parameter" do
27
+ params = {:limit => 2}
28
+ stub_get(build_url(@comments_url, params), "comments.json", params)
29
+ @client.comments(123, params).first.id.must_equal "1234"
30
+ end
31
+ end
32
+
33
+ describe "#comment(id)" do
34
+ before do
35
+ @note_id = '123'
36
+ @comment_id = '12345678'
37
+ @comment_url = "https://fooman:123123123@api.catch.com/v2/comment/123"
38
+ params = {:comment => @comment_id}
39
+ stub_get(build_url(@comment_url, params), "comment.json", params)
40
+ @comment = @client.comment(@note_id, @comment_id)
41
+ end
42
+
43
+ it "retrieves values a note" do
44
+ @comment.id.must_equal @comment_id
45
+ @comment.text.must_equal "Lorem ipsum dolor"
46
+ end
47
+ end
48
+
49
+ describe "#add_comment(options={})" do
50
+ before do
51
+ stub_post("https://fooman:123123123@api.catch.com/v2/comments/123", "comment.json")
52
+ end
53
+
54
+ it "adds a new comment to a note" do
55
+ comment = @client.add_comment(123, {:text => "Lorem ipsum dolor"})
56
+ comment.id.must_equal "12345678"
57
+ comment.text.must_equal "Lorem ipsum dolor"
58
+ end
59
+ end
60
+
61
+ describe "#modify_comment(note_id, comment_id, options={})" do
62
+ before do
63
+ @note_id = '123'
64
+ @comment_id = '12345678'
65
+ @comments_url = "https://fooman:123123123@api.catch.com/v2/comments/123"
66
+ end
67
+
68
+ it "returns the updated comment" do
69
+ params = {:comment => @comment_id, :text => "Foo%20bar%20baz"}
70
+ stub_post(build_url(@comments_url, params), "modified_comment.json", params)
71
+ comment = @client.modify_comment(@note_id, @comment_id, {:text => "Foo bar baz"})
72
+ comment.id.must_equal @comment_id
73
+ comment.text.must_equal "Foo bar baz"
74
+ end
75
+ end
76
+
77
+ describe "#delete_note(id)" do
78
+ before do
79
+ @note_id = '123'
80
+ @comment_id = '12345678'
81
+ stub_delete("https://fooman:123123123@api.catch.com/v2/comments/#{@note_id}?comment=#{@comment_id}", "comment_delete.json")
82
+ end
83
+
84
+ it "deletes a specified comment" do
85
+ comment = @client.delete_comment(@note_id, @comment_id)
86
+ comment.must_equal true
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,17 @@
1
+ {"count": 1,
2
+ "notes": [
3
+ {
4
+ "source": null,
5
+ "created_at": "2011-05-15T12:15:36.748Z",
6
+ "tags": [],
7
+ "modified_at": "2011-05-15T12:15:36.748Z",
8
+ "comments": [],
9
+ "source_url": "https:\/\/catch.com\/",
10
+ "text": "Lorem ipsum dolor",
11
+ "summary": "Lorem ipsum dolor",
12
+ "id": "12345678",
13
+ "user": {"user_name": "fooman", "id": "123456789"}
14
+ }],
15
+ "previous_cursor": 0,
16
+ "next_cursor": 0}
17
+
@@ -0,0 +1 @@
1
+ {"status": "ok"}
@@ -0,0 +1,31 @@
1
+ {
2
+ "count": 2,
3
+ "notes": [
4
+ {
5
+ "source": null,
6
+ "created_at": "2011-05-15T12:15:36.748Z",
7
+ "tags": [],
8
+ "modified_at": "2011-05-15T12:15:36.748Z",
9
+ "comments": [],
10
+ "source_url": "https:\/\/catch.com\/",
11
+ "text": "Lorem ipsum dolor1",
12
+ "summary": "Lorem ipsum dolor1",
13
+ "id": "1234",
14
+ "user": {"user_name": "fooman", "id": "12345678"}
15
+ },
16
+ {
17
+ "source": null,
18
+ "created_at": "2011-05-15T12:15:46.450Z",
19
+ "tags": [],
20
+ "modified_at": "2011-05-15T12:15:46.450Z",
21
+ "comments": [],
22
+ "source_url": "https:\/\/catch.com\/",
23
+ "text": "Lorem ipsum dolor2",
24
+ "summary": "Lorem ipsum dolor2",
25
+ "id": "1235",
26
+ "user": {"user_name": "fooman", "id": "12345678"}
27
+ }
28
+ ],
29
+ "previous_cursor": 0,
30
+ "next_cursor": 0
31
+ }
Binary file
@@ -0,0 +1,10 @@
1
+ {
2
+ "created_at": null,
3
+ "id": "123abc",
4
+ "note_id": "123",
5
+ "server_created_at": "2011-05-18T17:49:47.190Z",
6
+ "size":16361,
7
+ "src":"https://api.catch.com/v2/media/123123123123/123abc",
8
+ "type":"image/jpeg",
9
+ "voicenote_hint":false
10
+ }
@@ -0,0 +1 @@
1
+ {"status": "ok"}
@@ -0,0 +1,17 @@
1
+ {"count": 1,
2
+ "notes": [
3
+ {
4
+ "source": null,
5
+ "created_at": "2011-05-15T12:15:36.748Z",
6
+ "tags": [],
7
+ "modified_at": "2011-05-15T12:15:36.748Z",
8
+ "comments": [],
9
+ "source_url": "https:\/\/catch.com\/",
10
+ "text": "Foo bar baz",
11
+ "summary": "Foo bar baz",
12
+ "id": "12345678",
13
+ "user": {"user_name": "fooman", "id": "123456789"}
14
+ }],
15
+ "previous_cursor": 0,
16
+ "next_cursor": 0}
17
+
@@ -0,0 +1,26 @@
1
+ {
2
+ "status": "ok",
3
+ "count": 1,
4
+ "notes": [{
5
+ "browser_url": "https:\/\/catch.comhttps:\/\/catch.com\/m\/BX-wJ\/-ESuZmYBR50",
6
+ "public_url": null,
7
+ "server_created_at": "2011-02-20T13:57:59.835Z",
8
+ "reminder_at": "1970-01-01T00:00:00.000Z",
9
+ "source": "Catch",
10
+ "media": [],
11
+ "created_at": "2011-02-20T14:00:03.000Z",
12
+ "tags": ["quotes"],
13
+ "modified_at": "2011-02-21T16:23:16.037Z",
14
+ "comments": [],
15
+ "source_url": "https:\/\/catch.com\/",
16
+ "server_modified_at": "2011-02-21T16:23:16.037Z",
17
+ "location": null,
18
+ "text": "Foo bar baz",
19
+ "summary": "Lorem ipsum dolor",
20
+ "id": "12345678",
21
+ "user": {
22
+ "user_name": "fooman",
23
+ "id": "87654321"
24
+ }
25
+ }]
26
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "status": "ok",
3
+ "count": 1,
4
+ "notes": [{
5
+ "browser_url": "https:\/\/catch.comhttps:\/\/catch.com\/m\/BX-wJ\/-ESuZmYBR50",
6
+ "public_url": null,
7
+ "server_created_at": "2011-02-20T13:57:59.835Z",
8
+ "reminder_at": "1970-01-01T00:00:00.000Z",
9
+ "source": "Catch",
10
+ "media": [],
11
+ "created_at": "2011-02-20T14:00:03.000Z",
12
+ "tags": ["quotes"],
13
+ "modified_at": "2011-02-21T16:23:16.037Z",
14
+ "comments": [],
15
+ "source_url": "https:\/\/catch.com\/",
16
+ "server_modified_at": "2011-02-21T16:23:16.037Z",
17
+ "location": null,
18
+ "text": "Lorem ipsum dolor",
19
+ "summary": "Lorem ipsum dolor",
20
+ "id": "12345678",
21
+ "user": {
22
+ "user_name": "fooman",
23
+ "id": "87654321"
24
+ }
25
+ }]
26
+ }
@@ -0,0 +1 @@
1
+ {"status": "ok"}
@@ -0,0 +1,14 @@
1
+ {
2
+ "status": "ok",
3
+ "count": 40,
4
+ "notes": [
5
+ {"server_modified_at": "2011-05-09T02:21:20.304Z", "id": "12345678"},
6
+ {"server_modified_at": "2011-05-03T13:22:39.599Z", "id": "23456781"},
7
+ {"server_modified_at": "2011-05-01T03:18:33.489Z", "id": "34567812"},
8
+ {"server_modified_at": "2011-05-01T02:41:49.186Z", "id": "45678123"},
9
+ {"server_modified_at": "2011-04-27T13:37:51.295Z", "id": "56781234"},
10
+ {"server_modified_at": "2011-04-27T12:19:29.596Z", "id": "67812345"},
11
+ {"server_modified_at": "2011-04-27T12:18:57.392Z", "id": "78123456"},
12
+ {"server_modified_at": "2011-04-21T19:14:13.922Z", "id": "81234567"}
13
+ ]
14
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "status": "ok",
3
+ "count": 40,
4
+ "notes": [
5
+ {"server_modified_at": "2011-05-09T02:21:20.304Z", "id": "12345678"},
6
+ {"server_modified_at": "2011-05-03T13:22:39.599Z", "id": "23456781"},
7
+ {"server_modified_at": "2011-05-01T03:18:33.489Z", "id": "34567812"},
8
+ {"server_modified_at": "2011-05-01T02:41:49.186Z", "id": "45678123"},
9
+ {"server_modified_at": "2011-04-27T13:37:51.295Z", "id": "56781234"},
10
+ {"server_modified_at": "2011-04-27T12:19:29.596Z", "id": "67812345"},
11
+ {"server_modified_at": "2011-04-27T12:18:57.392Z", "id": "78123456"},
12
+ {"server_modified_at": "2011-04-21T19:14:13.922Z", "id": "81234567"}
13
+ ]
14
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "tags": [
3
+ {"count": 2, "name": "RoR", "modified": "2011-04-20T13:13:02.420Z"},
4
+ {"count": 2, "name": "agile", "modified": "2011-04-27T13:38:06.569Z"},
5
+ {"count": 1, "name": "bdd", "modified": "2011-05-14T12:00:16.765Z"},
6
+ {"count": 1, "name": "business", "modified": "2011-04-15T21:18:51.152Z"},
7
+ {"count": 1, "name": "change", "modified": "2011-04-15T21:19:02.382Z"},
8
+ {"count": 3, "name": "cli", "modified": "2011-05-11T17:27:25.361Z"},
9
+ {"count": 1, "name": "cucumber", "modified": "2011-05-14T12:00:16.765Z"},
10
+ {"count": 1, "name": "education", "modified": "2011-04-23T17:04:36.000Z"},
11
+ {"count": 1, "name": "formats", "modified": "2011-02-21T16:14:49.243Z"},
12
+ {"count": 1, "name": "git", "modified": "2011-02-21T16:22:42.051Z"},
13
+ {"count": 2, "name": "linux", "modified": "2011-05-11T17:27:25.361Z"},
14
+ {"count": 1, "name": "memory", "modified": "2011-03-09T01:20:56.000Z"},
15
+ {"count": 1, "name": "programming", "modified": "2011-03-09T01:49:10.000Z"},
16
+ {"count": 15, "name": "quotes", "modified": "2011-05-11T01:01:41.511Z"},
17
+ {"count": 1, "name": "refactoring", "modified": "2011-04-27T13:37:51.295Z"},
18
+ {"count": 4, "name": "ruby", "modified": "2011-05-14T12:00:16.765Z"},
19
+ {"count": 1, "name": "sql", "modified": "2011-02-21T16:09:09.614Z"},
20
+ {"count": 1, "name": "ubuntu", "modified": "2011-05-03T13:22:39.599Z"},
21
+ {"count": 2, "name": "xp", "modified": "2011-04-27T13:38:06.569Z"}
22
+ ]
23
+ }
24
+
@@ -0,0 +1,39 @@
1
+ {
2
+ "server_time": "2011-02-26T01:49:16.582Z",
3
+ "user": {
4
+ "account_level_desc": "Catch Free",
5
+ "created_at": "2011-02-26T00:50:59.795Z",
6
+ "deactivated_at": null,
7
+ "account_capabilities": {
8
+ "allowed_content_types": [
9
+ "audio/*",
10
+ "application/ogg",
11
+ "image/*",
12
+ "video/*"
13
+ ]
14
+ },
15
+ "account_subscription_end_advisory": null,
16
+ "linked_accounts": [],
17
+ "account_upload_activity": {
18
+ "2011-02": 6681
19
+ },
20
+ "id": "22878064",
21
+ "email": "info@catch.com",
22
+ "deactivateAccount": 0,
23
+ "account_upload_activity_periodic": [{
24
+ "period_start": "2011-02-26T00:00:00.000Z",
25
+ "period_activity": 6681,
26
+ "period_end": "2011-03-26T00:00:00.000Z"
27
+ }],
28
+ "user_name": "API Documenter",
29
+ "emails": [{
30
+ "confirmed": "2011-02-26T00:50:59.795Z",
31
+ "email": "info@catch.com",
32
+ "primary": true
33
+ }],
34
+ "account_limits": {
35
+ "monthly_upload_limit": 52428800
36
+ },
37
+ "account_level": 0
38
+ }
39
+ }
@@ -0,0 +1,60 @@
1
+ require 'minitest/autorun'
2
+ require 'fakeweb'
3
+
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+
7
+ require 'catch'
8
+
9
+ FakeWeb.allow_net_connect = false
10
+
11
+ def catch_test_client
12
+ Catch::Client.new(:username => 'fooman', :password => '123123123')
13
+ end
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
+ def catch_url(url)
22
+ url.match(/^http/) ? url : "https://api.catch.com/v2#{url}"
23
+ end
24
+
25
+ def stub_get(url, filename, options={})
26
+ opts = {
27
+ :body => fixture_file(filename),
28
+ :content_type => 'application/json; charset=utf-8'
29
+ }.merge(options)
30
+ FakeWeb.register_uri(:get, catch_url(url), opts)
31
+ end
32
+
33
+ def stub_post(url, filename, options={})
34
+ opts = {
35
+ :body => fixture_file(filename),
36
+ :content_type => 'application/json; charset=utf-8'
37
+ }.merge(options)
38
+ FakeWeb.register_uri(:post, catch_url(url), opts)
39
+ end
40
+
41
+ # only used for media
42
+ def stub_put(url, filename, options={})
43
+ opts = {
44
+ :body => fixture_file(filename),
45
+ :content_type => 'application/json; charset=utf-8'
46
+ }.merge(options)
47
+ FakeWeb.register_uri(:put, /#{catch_url(url)}/, opts)
48
+ end
49
+
50
+ def stub_delete(url, filename, options={})
51
+ opts = {
52
+ :body => fixture_file(filename),
53
+ :content_type => 'application/json; charset=utf-8'
54
+ }.merge(options)
55
+ FakeWeb.register_uri(:delete, catch_url(url), opts)
56
+ end
57
+
58
+ def build_url(url, params)
59
+ [url, params.map {|k,v| "#{k}=#{v}"}.join("&")].join("?")
60
+ end
@@ -0,0 +1,43 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'helper'
5
+
6
+ describe Catch::Media do
7
+ before do
8
+ @note_id = "123"
9
+ @media_id = "123abc"
10
+ @media_url = "https://fooman:123123123@api.catch.com/v2/media"
11
+ @client = catch_test_client
12
+ end
13
+
14
+ describe "#add_media(id, FILE)" do
15
+ before do
16
+ end
17
+
18
+ it "posts a file to an existing note" do
19
+ stub_put("#{@media_url}/#{@note_id}", "media.json")
20
+ media = @client.add_media(@note_id, "test/fixtures/media.jpg")
21
+ media.id.must_equal('123abc')
22
+ end
23
+ end
24
+
25
+ describe "#media" do
26
+ it "retrieves a media file" do
27
+ stub_get("#{@media_url}/#{@note_id}/#{@media_id}", "media.jpg")
28
+ media_file = @client.media(@note_id, @media_id)
29
+ puts media_file.size
30
+ end
31
+ end
32
+
33
+ describe "#delete_media(note_id, media_id)" do
34
+ before do
35
+ stub_delete("https://fooman:123123123@api.catch.com/v2/media/#{@note_id}/#{@media_id}", "note_delete.json")
36
+ end
37
+
38
+ it "deletes a specified media file from a note" do
39
+ media = @client.delete_media(@note_id, @media_id)
40
+ media.must_equal true
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,82 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'helper'
5
+
6
+ describe Catch::Note do
7
+ before do
8
+ @client = catch_test_client
9
+ end
10
+
11
+ describe "#notes" do
12
+ before do
13
+ @notes_url = "https://fooman:123123123@api.catch.com/v2/notes"
14
+ stub_get(@notes_url, "notes.json")
15
+ @notes = @client.notes
16
+ end
17
+
18
+ it "retrieves a list of notes as an array" do
19
+ @notes.must_be_instance_of Array
20
+ end
21
+
22
+ it "retrieves values from a note within the retrieved array" do
23
+ @notes.first.id.must_equal "12345678"
24
+ end
25
+
26
+ it "takes a hash as a parameter" do
27
+ params = {:limit => 2}
28
+ stub_get(build_url(@notes_url, params), "notes.json", params)
29
+ @client.notes(params).first.id.must_equal "12345678"
30
+ end
31
+ end
32
+
33
+ describe "#note(id)" do
34
+ before do
35
+ @id = '12345678'
36
+ stub_get("https://fooman:123123123@api.catch.com/v2/notes/#{@id}", "note.json")
37
+ @note = @client.note(@id)
38
+ end
39
+
40
+ it "retrieves values a note" do
41
+ @note.id.must_equal @id
42
+ @note.text.must_equal "Lorem ipsum dolor"
43
+ end
44
+ end
45
+
46
+ describe "#add_note(options={})" do
47
+ before do
48
+ stub_post("https://fooman:123123123@api.catch.com/v2/notes", "note.json")
49
+ end
50
+
51
+ it "adds a new note" do
52
+ note = @client.add_note({:text => "Lorem ipsum dolor"})
53
+ note.id.must_equal "12345678"
54
+ note.text.must_equal "Lorem ipsum dolor"
55
+ end
56
+ end
57
+
58
+ describe "#modify_note(id, options={})" do
59
+ before do
60
+ @id = '12345678'
61
+ stub_post("https://fooman:123123123@api.catch.com/v2/notes/#{@id}", "modified_note.json")
62
+ end
63
+
64
+ it "returns the updated note" do
65
+ note = @client.modify_note(@id, {:text => "Foo bar baz"})
66
+ note.id.must_equal @id
67
+ note.text.must_equal "Foo bar baz"
68
+ end
69
+ end
70
+
71
+ describe "#delete_note(id)" do
72
+ before do
73
+ @id = '123123'
74
+ stub_delete("https://fooman:123123123@api.catch.com/v2/notes/#{@id}", "note_delete.json")
75
+ end
76
+
77
+ it "deletes a specified note" do
78
+ note = @client.delete_note(@id)
79
+ note.must_equal true
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'helper'
5
+
6
+ describe Catch::Search do
7
+ before do
8
+ @client = catch_test_client
9
+ end
10
+
11
+ describe "#search" do
12
+ before do
13
+ @notes_url = "https://fooman:123123123@api.catch.com/v2/search"
14
+ # stub_get(@notes_url, "notes.json")
15
+ end
16
+
17
+ it "passes query and search parameters, and returns an array of notes" do
18
+ params = {:q => "Lorem%20ipsum"}
19
+ stub_get(build_url(@notes_url, params), "search.json", params)
20
+ notes = @client.search("Lorem ipsum")
21
+ notes.must_be_instance_of Array
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,27 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'helper'
5
+
6
+ describe Catch::Tag do
7
+ before do
8
+ @client = catch_test_client
9
+ end
10
+
11
+ describe "#tags" do
12
+ before do
13
+ @tags_url = "https://fooman:123123123@api.catch.com/v2/tags"
14
+ stub_get(@tags_url, "tags.json")
15
+ @tags = @client.tags
16
+ end
17
+
18
+ it "retrieves a users tag list" do
19
+ @tags.must_be_instance_of Array
20
+ end
21
+
22
+ it "retrieves values from a tag within the retrieved array" do
23
+ @tags.first.name.must_equal "RoR"
24
+ @tags.first['count'].must_equal 2
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'helper'
5
+
6
+ describe Catch::User do
7
+ before do
8
+ @client = catch_test_client
9
+ end
10
+
11
+ describe "#user" do
12
+ before do
13
+ stub_get("https://fooman:123123123@api.catch.com/v2/user", "user.json")
14
+ @user = @client.user
15
+ end
16
+
17
+ it "retrieves the user record" do
18
+ @user.account_level_desc.must_equal "Catch Free"
19
+ @user.user_name.must_equal "API Documenter"
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: catch
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Samuel Mullen
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-05-18 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: hashie
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 0
31
+ - 0
32
+ version: 1.0.0
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: faraday
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ - 6
46
+ - 1
47
+ version: 0.6.1
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: faraday_middleware
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ - 6
61
+ - 3
62
+ version: 0.6.3
63
+ type: :runtime
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: bundler
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 1
75
+ - 0
76
+ - 0
77
+ version: 1.0.0
78
+ type: :development
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: fakeweb
82
+ prerelease: false
83
+ requirement: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 1
90
+ - 3
91
+ - 0
92
+ version: 1.3.0
93
+ type: :development
94
+ version_requirements: *id005
95
+ description: Ruby wrapper for Catch.com's API
96
+ email:
97
+ - samullen@gmail.com
98
+ executables: []
99
+
100
+ extensions: []
101
+
102
+ extra_rdoc_files: []
103
+
104
+ files:
105
+ - .gitignore
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - README.md
109
+ - Rakefile
110
+ - catch.gemspec
111
+ - lib/catch.rb
112
+ - lib/catch/client.rb
113
+ - lib/catch/comment.rb
114
+ - lib/catch/media.rb
115
+ - lib/catch/note.rb
116
+ - lib/catch/search.rb
117
+ - lib/catch/tag.rb
118
+ - lib/catch/user.rb
119
+ - lib/catch/version.rb
120
+ - test/client_test.rb
121
+ - test/comment_test.rb
122
+ - test/fixtures/comment.json
123
+ - test/fixtures/comment_delete.json
124
+ - test/fixtures/comments.json
125
+ - test/fixtures/media.jpg
126
+ - test/fixtures/media.json
127
+ - test/fixtures/media_delete.json
128
+ - test/fixtures/modified_comment.json
129
+ - test/fixtures/modified_note.json
130
+ - test/fixtures/note.json
131
+ - test/fixtures/note_delete.json
132
+ - test/fixtures/notes.json
133
+ - test/fixtures/search.json
134
+ - test/fixtures/tags.json
135
+ - test/fixtures/user.json
136
+ - test/helper.rb
137
+ - test/media_test.rb
138
+ - test/note_test.rb
139
+ - test/search_test.rb
140
+ - test/tag_test.rb
141
+ - test/user_test.rb
142
+ has_rdoc: true
143
+ homepage: http://rubygems.org/gems/catch
144
+ licenses: []
145
+
146
+ post_install_message:
147
+ rdoc_options: []
148
+
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ segments:
165
+ - 1
166
+ - 3
167
+ - 6
168
+ version: 1.3.6
169
+ requirements: []
170
+
171
+ rubyforge_project: catch
172
+ rubygems_version: 1.3.7
173
+ signing_key:
174
+ specification_version: 3
175
+ summary: Ruby wrapper for Catch.com's API
176
+ test_files: []
177
+