active_diigo 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Bagwan Pankaj
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.markdown ADDED
@@ -0,0 +1,53 @@
1
+ ## ActiveDiigo
2
+
3
+ ##### Description
4
+
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
+
7
+ ##### Installation
8
+
9
+ as you install any other ruby gem
10
+ [sudo] gem install active_diigo
11
+
12
+ using bundler
13
+ gem 'active_diigo'
14
+
15
+ and then
16
+ bundle install
17
+
18
+ ##### Uses
19
+
20
+ Setup API Key and user credentials in initializer or anywhere before using active_diigo
21
+ ActiveDiigo.api_key = 'YOUR_API_KEY'
22
+ ActiveDiigo.username = '<user-name>'
23
+ ActiveDiigo.username = '<password>'
24
+
25
+ then
26
+
27
+ ActiveDiigo::Base.find(username, options)
28
+ #=> returns array of ActiveDiigo::Base objects
29
+ ActiveDiigo::Base.save(title, url, options)
30
+ #=> returns a hash with message (saved or not)
31
+ #OR
32
+ class MyDiigo < ActiveDiigo::Base; end
33
+ MyDiigo.find(username, options)
34
+ #=> Returns array of MyDiigo objects
35
+
36
+ ##### Contributing to active_diigo
37
+
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.
45
+
46
+ ##### TODO
47
+
48
+ * Chaining and scoping for query parameters
49
+
50
+ ##### Copyright
51
+
52
+ Copyright (c) 2011 Bagwan Pankaj. See LICENSE for further details.
53
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,39 @@
1
+ # Copyright (c) 2011 Bagwan Pankaj
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.
21
+
22
+ require 'httparty'
23
+ require 'json'
24
+
25
+ require 'active_diigo'
26
+ require 'active_diigo/base'
27
+ require 'active_diigo/errors'
28
+ require 'active_diigo/request'
29
+ require 'active_diigo/response_object'
30
+
31
+ module ActiveDiigo
32
+
33
+ class << self; attr_accessor :api_key, :username, :password; end
34
+
35
+ def self.version
36
+ File.read(File.join(File.dirname(__FILE__), '..', 'VERSION'))
37
+ end
38
+
39
+ end
@@ -0,0 +1,63 @@
1
+ # Copyright (c) 2011 Bagwan Pankaj
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.
21
+
22
+ module ActiveDiigo
23
+
24
+ class Base
25
+
26
+ class << self; attr_reader :request; end
27
+ attr_accessor :title, :url, :user, :desc, :tags, :shared, :created_at, :updated_at, :comments, :annotations, :readlater
28
+
29
+ def initialize(options)
30
+ build_self(options)
31
+ end
32
+
33
+ def self.find(user, options = {})
34
+ options.merge!({:user => user})
35
+ ResponseObject.new(connection.bookmarks(options), self).parsed_objects
36
+ end
37
+
38
+ def self.save(title, url, options = {})
39
+ options.merge!({:title => title, :url => url})
40
+ connection.save
41
+ end
42
+
43
+ private
44
+
45
+ def self.active_request_connection
46
+ username, password = assign_access_credentials!
47
+ Request.new(username, password)
48
+ end
49
+ class << self; alias_method :connection, :active_request_connection; end
50
+
51
+ def self.assign_access_credentials!
52
+ [ActiveDiigo.username, ActiveDiigo.password]
53
+ end
54
+
55
+ def build_self(options)
56
+ options.each do |k,v|
57
+ send(:"#{k}=", v) if send(:respond_to?, :"#{k}=")
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ end
@@ -0,0 +1,53 @@
1
+ # Copyright (c) 2011 Bagwan Pankaj
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.
21
+
22
+ module ActiveDiigo
23
+
24
+ module Errors
25
+ class ActiveDiigoError < StandardError
26
+ def initialize(status_code)
27
+ super("ActiveDiigo status #{status_code} - #{self.class}")
28
+ end
29
+ end
30
+ class NotAuthorizedError < ActiveDiigoError
31
+ def initialize; super(401); end
32
+ end
33
+ class ForbiddenError < ActiveDiigoError
34
+ def initialize; super(403); end
35
+ end
36
+ class BadRequestError < ActiveDiigoError
37
+ def initialize; super(400); end
38
+ end
39
+ class NotFoundError < ActiveDiigoError
40
+ def initialize; super(404); end
41
+ end
42
+ class InternalServerError < ActiveDiigoError
43
+ def initialize; super(500); end
44
+ end
45
+ class BadGatewayError < ActiveDiigoError
46
+ def initialize; super(502); end
47
+ end
48
+ class ServiceUnavailableError < ActiveDiigoError
49
+ def initialize; super(503); end
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,46 @@
1
+ # Copyright (c) 2011 Bagwan Pankaj
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.
21
+
22
+ module ActiveDiigo
23
+ class Request
24
+
25
+ include HTTParty
26
+
27
+ base_uri 'https://secure.diigo.com/api/v2'
28
+
29
+ API_VERSION = 'v2'
30
+
31
+ def initialize(uname, password)
32
+ self.class.basic_auth uname, password
33
+ end
34
+
35
+ def bookmarks(options = {})
36
+ options.merge!({:key => ActiveDiigo.api_key})
37
+ self.class.get('/bookmarks', {:query => options})
38
+ end
39
+
40
+ def save(options = {})
41
+ options.merge!({:key => ActiveDiigo.api_key})
42
+ self.class.post('/bookmarks', {:body => options})
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,62 @@
1
+ # Copyright (c) 2011 Bagwan Pankaj
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.
21
+
22
+ module ActiveDiigo
23
+
24
+ class ResponseObject
25
+
26
+ attr_reader :raw_response, :parsed_response, :parsed_objects
27
+
28
+ def initialize(http_response, receiver_klass)
29
+ @raw_response, @receiver_klass = http_response, receiver_klass
30
+ validate_response!
31
+ @parsed_objects = build_objects
32
+ end
33
+
34
+ private
35
+
36
+ def build_object(options)
37
+ @receiver_klass.new(options)
38
+ end
39
+
40
+ def build_objects
41
+ parse! and @parsed_response.collect{|pr| build_object(pr) }
42
+ end
43
+
44
+ def parse!
45
+ @parsed_response = JSON.parse(@raw_response)
46
+ end
47
+
48
+ def validate_response!
49
+ case @raw_response.response.class.to_s
50
+ when Net::HTTPUnauthorized.to_s then raise ActiveDiigo::Errors::NotAuthorizedError.new
51
+ when Net::HTTPBadRequest.to_s then raise ActiveDiigo::Errors::BadRequestError.new
52
+ when Net::HTTPForbidden.to_s then raise ActiveDiigo::Errors::ForbiddenError.new
53
+ when Net::HTTPNotFound.to_s then raise ActiveDiigo::Errors::NotFoundError.new
54
+ when Net::HTTPInternalServerError.to_s then raise ActiveDiigo::Errors::InternalServerError.new
55
+ when Net::HTTPServiceUnavailable.to_s then raise ActiveDiigo::Errors::ServiceUnavailableError.new
56
+ when Net::HTTPBadGateway.to_s then raise ActiveDiigo::Errors::BadGatewayError.new
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "ActiveDiigo" do
4
+ # it "fails" do
5
+ # fail "hey buddy, you should probably rename this file and start specing for real"
6
+ # end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'active_diigo'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_diigo
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Bagwan Pankaj
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-30 00:00:00 +05:30
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ prerelease: false
24
+ name: httparty
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ type: :runtime
37
+ prerelease: false
38
+ name: json
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ requirement: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ type: :development
51
+ prerelease: false
52
+ name: rspec
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 11
59
+ segments:
60
+ - 2
61
+ - 1
62
+ - 0
63
+ version: 2.1.0
64
+ requirement: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ type: :development
67
+ prerelease: false
68
+ name: yard
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 7
75
+ segments:
76
+ - 0
77
+ - 6
78
+ - 0
79
+ version: 0.6.0
80
+ requirement: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ type: :development
83
+ prerelease: false
84
+ name: bundler
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ hash: 23
91
+ segments:
92
+ - 1
93
+ - 0
94
+ - 0
95
+ version: 1.0.0
96
+ requirement: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ type: :development
99
+ prerelease: false
100
+ name: jeweler
101
+ version_requirements: &id006 !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ~>
105
+ - !ruby/object:Gem::Version
106
+ hash: 7
107
+ segments:
108
+ - 1
109
+ - 5
110
+ - 2
111
+ version: 1.5.2
112
+ requirement: *id006
113
+ - !ruby/object:Gem::Dependency
114
+ type: :development
115
+ prerelease: false
116
+ name: rcov
117
+ version_requirements: &id007 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ requirement: *id007
127
+ description: "ActiveDiigo is a wrapper for Diigo API(version: v2)."
128
+ email: me@bagwanpankaj.com
129
+ executables: []
130
+
131
+ extensions: []
132
+
133
+ extra_rdoc_files:
134
+ - LICENSE.txt
135
+ - README.markdown
136
+ files:
137
+ - LICENSE.txt
138
+ - VERSION
139
+ - lib/active_diigo.rb
140
+ - lib/active_diigo/base.rb
141
+ - lib/active_diigo/errors.rb
142
+ - lib/active_diigo/request.rb
143
+ - lib/active_diigo/response_object.rb
144
+ - README.markdown
145
+ - spec/active_diigo_spec.rb
146
+ - spec/spec_helper.rb
147
+ has_rdoc: true
148
+ homepage: http://github.com/bagwanpankaj/active_diigo
149
+ licenses:
150
+ - MIT
151
+ post_install_message:
152
+ rdoc_options: []
153
+
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ hash: 3
162
+ segments:
163
+ - 0
164
+ version: "0"
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ hash: 3
171
+ segments:
172
+ - 0
173
+ version: "0"
174
+ requirements: []
175
+
176
+ rubyforge_project:
177
+ rubygems_version: 1.3.7
178
+ signing_key:
179
+ specification_version: 3
180
+ summary: Diigo Restful API wrapper; much like ActiveRecord
181
+ test_files:
182
+ - spec/active_diigo_spec.rb
183
+ - spec/spec_helper.rb