active_diigo 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +34 -30
- data/VERSION +1 -1
- data/lib/active_diigo/base.rb +1 -1
- data/spec/active_diigo_spec.rb +100 -3
- data/spec/spec_helper.rb +4 -0
- data/spec/support/fake_web_stub.rb +15 -0
- metadata +20 -4
data/README.markdown
CHANGED
@@ -1,53 +1,57 @@
|
|
1
1
|
## ActiveDiigo
|
2
2
|
|
3
|
-
|
3
|
+
### Description
|
4
4
|
|
5
5
|
ActiveDiigo is a wrapper for Diigo API(version: v2). It provides ActiveRecord like interaction with Diigo API. You just need to inherit ActiveDiigo::Base in class you want to use active_diigo in. It's also works standalone and it's framework agnostic gem, enabling itself to be used in any ruby framework.
|
6
6
|
|
7
|
-
|
7
|
+
### Installation
|
8
8
|
|
9
9
|
as you install any other ruby gem
|
10
|
-
|
10
|
+
|
11
|
+
[sudo] gem install active_diigo
|
11
12
|
|
12
13
|
using bundler
|
13
|
-
|
14
|
+
|
15
|
+
gem 'active_diigo'
|
14
16
|
|
15
17
|
and then
|
16
|
-
bundle install
|
17
18
|
|
18
|
-
|
19
|
+
bundle install
|
20
|
+
|
21
|
+
### Uses
|
19
22
|
|
20
23
|
Setup API Key and user credentials in initializer or anywhere before using active_diigo
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
|
25
|
+
ActiveDiigo.api_key = 'YOUR_API_KEY'
|
26
|
+
ActiveDiigo.username = '<user-name>'
|
27
|
+
ActiveDiigo.username = '<password>'
|
24
28
|
|
25
29
|
then
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
|
31
|
+
ActiveDiigo::Base.find(username, options)
|
32
|
+
#=> returns array of ActiveDiigo::Base objects
|
33
|
+
ActiveDiigo::Base.save(title, url, options)
|
34
|
+
#=> returns a hash with message (saved or not)
|
35
|
+
#OR
|
36
|
+
class MyDiigo < ActiveDiigo::Base; end
|
37
|
+
MyDiigo.find(username, options)
|
38
|
+
#=> Returns array of MyDiigo objects
|
39
|
+
|
40
|
+
### Contributing to active_diigo
|
37
41
|
|
38
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
39
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
40
|
-
* Fork the project
|
41
|
-
* Start a feature/bugfix branch
|
42
|
-
* Commit and push until you are happy with your contribution
|
43
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
44
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
42
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
43
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
44
|
+
* Fork the project
|
45
|
+
* Start a feature/bugfix branch
|
46
|
+
* Commit and push until you are happy with your contribution
|
47
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
48
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
45
49
|
|
46
|
-
|
50
|
+
### TODO
|
47
51
|
|
48
|
-
* Chaining and scoping for query parameters
|
52
|
+
* Chaining and scoping for query parameters
|
49
53
|
|
50
|
-
|
54
|
+
### Copyright
|
51
55
|
|
52
56
|
Copyright (c) 2011 Bagwan Pankaj. See LICENSE for further details.
|
53
57
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/active_diigo/base.rb
CHANGED
data/spec/active_diigo_spec.rb
CHANGED
@@ -1,7 +1,104 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe "ActiveDiigo" do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
|
5
|
+
describe ActiveDiigo::Request do
|
6
|
+
before(:all) do
|
7
|
+
ActiveDiigo.api_key = 'TEST_API_KEY'
|
8
|
+
@base_uri = "https://secure.diigo.com/api/v2"
|
9
|
+
end
|
10
|
+
it "should have HTTParty included" do
|
11
|
+
ActiveDiigo::Request.should include HTTParty
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should have base_uri set as diigo api uri" do
|
15
|
+
ActiveDiigo::Request.base_uri.should == @base_uri
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have API version v2 for diigo API" do
|
19
|
+
ActiveDiigo::Request::API_VERSION.should == 'v2'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should raise ArgumentError when not initialized with with proper no of argument" do
|
23
|
+
Proc.new do
|
24
|
+
ActiveDiigo::Request.new()
|
25
|
+
end.should raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not raise error when initialized properly" do
|
29
|
+
Proc.new do
|
30
|
+
ActiveDiigo::Request.new('user', 'pass')
|
31
|
+
end.should_not raise_error(ArgumentError)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should send a 10 bookmarks in json format by default when requested" do
|
35
|
+
mock_request_for("https://test-user:test-pass@secure.diigo.com/api/v2/bookmarks?user=test-user&key=TEST_API_KEY")
|
36
|
+
|
37
|
+
con = ActiveDiigo::Request.new('test-user', 'test-pass')
|
38
|
+
res = con.bookmarks(:user => 'test-user')
|
39
|
+
res.parsed_response.should be_an_instance_of Array
|
40
|
+
res.size.should == 10
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should get error json while saving bookmark without required params" do
|
44
|
+
mock_request_for("https://test-user:test-pass@secure.diigo.com/api/v2/bookmarks", :method => :post,
|
45
|
+
:fixture => 'save_error')
|
46
|
+
con = ActiveDiigo::Request.new('test-user', 'test-pass')
|
47
|
+
res = con.save()
|
48
|
+
res["message"].should == "Error detected. Please check your input. Contact service@diigo.com if there's any problem."
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should get success json while saving bookmark" do
|
52
|
+
mock_request_for("https://test-user:test-pass@secure.diigo.com/api/v2/bookmarks", :method => :post,
|
53
|
+
:fixture => 'save_success')
|
54
|
+
con = ActiveDiigo::Request.new('test-user', 'test-pass')
|
55
|
+
res = con.save(:title => "my bookmark", :url => "http://mybookmark.com")
|
56
|
+
res["message"].should == "Saved 1 bookmark(s)"
|
57
|
+
res['code'].should == 1
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
describe ActiveDiigo::Base do
|
63
|
+
|
64
|
+
before(:all) do
|
65
|
+
ActiveDiigo.api_key = 'TEST_API_KEY'
|
66
|
+
ActiveDiigo.username = 'test-user'
|
67
|
+
ActiveDiigo.password = 'test-pass'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should find bookmarks with user test-user and return 10 bookmarks defaultly" do
|
71
|
+
mock_request_for("https://test-user:test-pass@secure.diigo.com/api/v2/bookmarks?user=test-user&key=TEST_API_KEY")
|
72
|
+
|
73
|
+
response = ActiveDiigo::Base.find('test-user')
|
74
|
+
response.size.should == 10
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "Misc" do
|
80
|
+
describe ActiveDiigo::Errors do
|
81
|
+
|
82
|
+
before(:all) do
|
83
|
+
@base_name = "ActiveDiigo::Errors::ActiveDiigoError"
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should inherit from Standard Error" do
|
87
|
+
ActiveDiigo::Errors::ActiveDiigoError.superclass.name.should == "StandardError"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should have various error classes implemented" do
|
91
|
+
ActiveDiigo::Errors::ActiveDiigoError.name.should == @base_name
|
92
|
+
ActiveDiigo::Errors::NotAuthorizedError.superclass.name.should == @base_name
|
93
|
+
ActiveDiigo::Errors::ForbiddenError.superclass.name.should == @base_name
|
94
|
+
ActiveDiigo::Errors::BadRequestError.superclass.name.should == @base_name
|
95
|
+
ActiveDiigo::Errors::NotFoundError.superclass.name.should == @base_name
|
96
|
+
ActiveDiigo::Errors::InternalServerError.superclass.name.should == @base_name
|
97
|
+
ActiveDiigo::Errors::BadGatewayError.superclass.name.should == @base_name
|
98
|
+
ActiveDiigo::Errors::ServiceUnavailableError.superclass.name.should == @base_name
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
7
104
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
3
|
require 'rspec'
|
4
|
+
require 'fakeweb'
|
4
5
|
require 'active_diigo'
|
5
6
|
|
6
7
|
# Requires supporting files with custom matchers and macros, etc,
|
7
8
|
# in ./support/ and its subdirectories.
|
8
9
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
10
|
|
11
|
+
include FakewebStub
|
12
|
+
FakeWeb.allow_net_connect = false
|
13
|
+
|
10
14
|
RSpec.configure do |config|
|
11
15
|
|
12
16
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module FakewebStub
|
2
|
+
|
3
|
+
def mock_request_for(url, options = {})
|
4
|
+
method = options[:method] || :get
|
5
|
+
fixture = options[:fixture] || 'bookmarks'
|
6
|
+
content_type = options[:content_type] || "application/json"
|
7
|
+
body = begin
|
8
|
+
File.read(File.expand_path(File.dirname(__FILE__)) + "/../fixtures/#{fixture}.json")
|
9
|
+
rescue Errno::ENOENT
|
10
|
+
raise "Could not find fixture file named '#{fixture}'!"
|
11
|
+
end
|
12
|
+
|
13
|
+
FakeWeb.register_uri(method, url, :body => body, :status => ["200", "OK"], :content_type => content_type)
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_diigo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bagwan Pankaj
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-02-02 00:00:00 +05:30
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -124,6 +124,20 @@ dependencies:
|
|
124
124
|
- 0
|
125
125
|
version: "0"
|
126
126
|
requirement: *id007
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
type: :development
|
129
|
+
prerelease: false
|
130
|
+
name: fakeweb
|
131
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
hash: 3
|
137
|
+
segments:
|
138
|
+
- 0
|
139
|
+
version: "0"
|
140
|
+
requirement: *id008
|
127
141
|
description: "ActiveDiigo is a wrapper for Diigo API(version: v2)."
|
128
142
|
email: me@bagwanpankaj.com
|
129
143
|
executables: []
|
@@ -144,6 +158,7 @@ files:
|
|
144
158
|
- README.markdown
|
145
159
|
- spec/active_diigo_spec.rb
|
146
160
|
- spec/spec_helper.rb
|
161
|
+
- spec/support/fake_web_stub.rb
|
147
162
|
has_rdoc: true
|
148
163
|
homepage: http://github.com/bagwanpankaj/active_diigo
|
149
164
|
licenses:
|
@@ -181,3 +196,4 @@ summary: Diigo Restful API wrapper; much like ActiveRecord
|
|
181
196
|
test_files:
|
182
197
|
- spec/active_diigo_spec.rb
|
183
198
|
- spec/spec_helper.rb
|
199
|
+
- spec/support/fake_web_stub.rb
|