cloudapp_api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Aaron Russell
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.md ADDED
@@ -0,0 +1,101 @@
1
+ # CloudApp API
2
+
3
+ A simple Ruby wrapper for the [CloudApp API](http://support.getcloudapp.com/faqs/developers/api). Uses [HTTParty](http://github.com/jnunemaker/httparty) with a simple ActiveResource-like interface.
4
+
5
+ Note: This is functional, but very much a work in progress.
6
+
7
+ ## TODO
8
+
9
+ * Get file uploads working
10
+ * Add tests
11
+ * Improve the docs
12
+
13
+ ## Installation
14
+
15
+ To install as a Gem:
16
+
17
+ sudo gem install cloudapp_api
18
+
19
+ ## Usage
20
+
21
+ ### Authentication
22
+
23
+ Authentication isn't necessary if you are just attempting to find an individual item. However, if you are trying to create, delete or list all items, you must authenticate.
24
+
25
+ CloudApp.authenticate "email@address.com", "password"
26
+
27
+ ### Initialize client interface
28
+
29
+ If you are using the client interface, you must create a client instance.
30
+
31
+ # Optionally you can pass a hash containing :username and :password to authenticate.
32
+
33
+ client = CloudApp::Client.new opts
34
+
35
+ ### View an item by short URL
36
+
37
+ short_url = "19xM"
38
+
39
+ @item = client.item short_url
40
+
41
+ # or ..
42
+
43
+ @item = CloudApp::Item.find short_url
44
+
45
+ ### List items
46
+
47
+ # Allowed params
48
+ # :page => 1 # page number starting at 1
49
+ # :per_page => 5 # number of items per page
50
+ # :type => "image" # filter items by type
51
+ # (image, bookmark, text, archive, audio, video, or unknown)
52
+ # :deleted => true # show trashed items
53
+
54
+ @items = client.items params
55
+
56
+ # or ..
57
+
58
+ @items = CloudApp::Item.all params
59
+
60
+ ### Create a bookmark
61
+
62
+ @item = client.bookmark url, name
63
+
64
+ # or ..
65
+
66
+ @item = CloudApp::Item.create :bookmark, {:name => name, :redirect_url => url}
67
+
68
+ ### Upload a file
69
+
70
+ NOTE! This is not working yet
71
+
72
+ @item = client.upload file_name
73
+
74
+ # or ..
75
+
76
+ @item = CloudApp::Item.create :file, {:path => file_name}
77
+
78
+ ### Delete an item
79
+
80
+ client.delete short_url
81
+
82
+ # or ..
83
+
84
+ @item.delete
85
+
86
+ ## Note on Patches/Pull Requests
87
+
88
+ * Fork the project.
89
+ * Make your feature addition or bug fix.
90
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
91
+ * Commit, do not mess with rakefile, version, or history.
92
+ (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)
93
+ * Send me a pull request. Bonus points for topic branches.
94
+
95
+ ## Author
96
+
97
+ * [Aaron Russell](http://www.aaronrussell.co.uk)
98
+
99
+ ## Copyright
100
+
101
+ Copyright (c) 2010 Aaron Russell. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "cloudapp_api"
8
+ gem.summary = %Q{A simple Ruby wrapper for the CloudApp API. Uses HTTParty with a simple ActiveResource-like interface.}
9
+ gem.description = %Q{A simple Ruby wrapper for the CloudApp API. Uses HTTParty with a simple ActiveResource-like interface.}
10
+ gem.email = "aaron@gc4.co.uk"
11
+ gem.homepage = "http://github.com/aaronrussell/cloud_app"
12
+ gem.authors = ["Aaron Russell"]
13
+ gem.add_dependency "httparty", ">= 0.5.2"
14
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "cloudly #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{cloudapp_api}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Aaron Russell"]
12
+ s.date = %q{2010-05-17}
13
+ s.description = %q{A simple Ruby wrapper for the CloudApp API. Uses HTTParty with a simple ActiveResource-like interface.}
14
+ s.email = %q{aaron@gc4.co.uk}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.md",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "cloudapp_api.gemspec",
27
+ "lib/cloudapp/base.rb",
28
+ "lib/cloudapp/client.rb",
29
+ "lib/cloudapp/httparty.rb",
30
+ "lib/cloudapp/monkey_patch/httparty.rb",
31
+ "lib/cloudapp/monkey_patch/net_digest_auth.rb",
32
+ "lib/cloudapp_api.rb",
33
+ "test/helper.rb",
34
+ "test/test_cloudly.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/aaronrussell/cloud_app}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.6}
40
+ s.summary = %q{A simple Ruby wrapper for the CloudApp API. Uses HTTParty with a simple ActiveResource-like interface.}
41
+ s.test_files = [
42
+ "test/helper.rb",
43
+ "test/test_cloudly.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<httparty>, [">= 0.5.2"])
52
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
53
+ else
54
+ s.add_dependency(%q<httparty>, [">= 0.5.2"])
55
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<httparty>, [">= 0.5.2"])
59
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
60
+ end
61
+ end
62
+
@@ -0,0 +1,66 @@
1
+ require "httparty"
2
+
3
+ module CloudApp
4
+
5
+ class Base
6
+
7
+ include HTTParty
8
+ base_uri "my.cl.ly"
9
+ headers "Accept" => "application/json", "Content-Type" => "application/json"
10
+ format :json
11
+
12
+ def self.authenticate(username, password)
13
+ @@auth = {:username => username, :password => password}
14
+ end
15
+
16
+ def self.find(id)
17
+ res = get("http://cl.ly/#{id}")
18
+ res.ok? ? Item.new(res) : res
19
+ end
20
+
21
+ def self.all(opts = {})
22
+ res = get("/items", opts.merge!(:digest_auth => @@auth))
23
+ res.ok? ? res.collect{|i| Item.new(i)} : res
24
+ end
25
+
26
+ def self.create(kind, opts = {})
27
+ case kind
28
+ when :bookmark
29
+ res = post "/items", {:digest_auth => @@auth, :query => opts}
30
+ res.ok? ? Item.new(res) : res
31
+ when :file
32
+ res = get "/items/new", {:digest_auth => @@auth}
33
+ return res unless res.ok?
34
+ res = post res['url'], {
35
+ :headers => {"Content-Type" => "multipart/form-data"},
36
+ :params => res['params'].merge!(:file => "@#{opts[:path]}")
37
+ }
38
+ res.ok? ? Item.new(res) : res
39
+ else
40
+ false
41
+ end
42
+ end
43
+
44
+ attr_accessor :attributes
45
+
46
+ def initialize(attributes = {})
47
+ load(attributes)
48
+ end
49
+
50
+ def delete
51
+ res = self.class.delete(self.href, :digest_auth => @@auth)
52
+ res.ok? ? true : res
53
+ end
54
+
55
+ def load(attributes = {})
56
+ attributes.each do |key, val|
57
+ self.instance_variable_set("@#{key}", val)
58
+ self.class.send(:define_method, key, proc{self.instance_variable_get("@#{key}")})
59
+ end
60
+ end
61
+
62
+ end
63
+
64
+ class Item < Base ; end
65
+
66
+ end
@@ -0,0 +1,37 @@
1
+ module CloudApp
2
+
3
+ class Client
4
+
5
+ def initialize(opts = {})
6
+ if opts[:username] && opts[:password]
7
+ Base.authenticate(opts[:username], opts[:password])
8
+ end
9
+ end
10
+
11
+ def authenticate(username, password)
12
+ Base.authenticate(username, password)
13
+ end
14
+
15
+ def item(id)
16
+ Item.find(id)
17
+ end
18
+
19
+ def items(opts = {})
20
+ Item.all(opts)
21
+ end
22
+
23
+ def bookmark(url, name = "")
24
+ Item.create(:bookmark, :item => {:name => name, :redirect_url => url})
25
+ end
26
+
27
+ def upload(file)
28
+ Item.create(:file, :path => file)
29
+ end
30
+
31
+ def delete(id)
32
+ Item.find(id).delete
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,13 @@
1
+ if HTTParty::VERSION <= "0.5.2"
2
+ ["httparty", "net_digest_auth"].each do |inc|
3
+ require File.join(File.dirname(__FILE__), "monkey_patch", inc)
4
+ end
5
+ end
6
+
7
+ module HTTParty
8
+ class Response < HTTParty::BasicObject
9
+ def ok?
10
+ @code == 200
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,42 @@
1
+ module HTTParty
2
+
3
+ module ClassMethods
4
+ def digest_auth(u, p)
5
+ default_options[:digest_auth] = {:username => u, :password => p}
6
+ end
7
+ end
8
+
9
+ class Request
10
+
11
+ private
12
+
13
+ def credentials
14
+ options[:basic_auth] || options[:digest_auth]
15
+ end
16
+
17
+ def username
18
+ credentials[:username]
19
+ end
20
+
21
+ def password
22
+ credentials[:password]
23
+ end
24
+
25
+ def setup_raw_request
26
+ @raw_request = http_method.new(uri.request_uri)
27
+ @raw_request.body = body if body
28
+ @raw_request.initialize_http_header(options[:headers])
29
+ @raw_request.basic_auth(username, password) if options[:basic_auth]
30
+ setup_digest_auth if options[:digest_auth]
31
+ end
32
+
33
+ def setup_digest_auth
34
+ res = http.head(uri.request_uri, options[:headers])
35
+ if res['www-authenticate'] != nil && res['www-authenticate'].length > 0
36
+ @raw_request.digest_auth(username, password, res)
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,35 @@
1
+ require 'digest/md5'
2
+ require 'net/http'
3
+
4
+ module Net
5
+ module HTTPHeader
6
+ def digest_auth(user, password, response)
7
+ response['www-authenticate'] =~ /^(\w+) (.*)/
8
+
9
+ params = {}
10
+ $2.gsub(/(\w+)="(.*?)"/) { params[$1] = $2 }
11
+ params.merge!("cnonce" => Digest::MD5.hexdigest("%x" % (Time.now.to_i + rand(65535))))
12
+
13
+ a_1 = Digest::MD5.hexdigest("#{user}:#{params['realm']}:#{password}")
14
+ a_2 = Digest::MD5.hexdigest("#{@method}:#{@path}")
15
+
16
+ request_digest = Digest::MD5.hexdigest(
17
+ [a_1, params['nonce'], "0", params['cnonce'], params['qop'], a_2].join(":")
18
+ )
19
+
20
+ header = [
21
+ %Q(Digest username="#{user}"),
22
+ %Q(realm="#{params['realm']}"),
23
+ %Q(qop="#{params['qop']}"),
24
+ %Q(uri="#{@path}"),
25
+ %Q(nonce="#{params['nonce']}"),
26
+ %Q(nc="0"),
27
+ %Q(cnonce="#{params['cnonce']}"),
28
+ %Q(opaque="#{params['opaque']}"),
29
+ %Q(response="#{request_digest}")
30
+ ]
31
+
32
+ @header['Authorization'] = header
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ require "httparty"
2
+
3
+ ["base", "client", "httparty"].each do |inc|
4
+ require File.join(File.dirname(__FILE__), "cloudapp", inc)
5
+ end
6
+
7
+ module CloudApp
8
+
9
+ VERSION = "0.0.1"
10
+
11
+ def CloudApp.authenticate(username, password)
12
+ Base.authenticate(username, password)
13
+ end
14
+
15
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
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 'cloudly'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestCloudAppAPI < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloudapp_api
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
+ - Aaron Russell
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-17 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: httparty
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 5
30
+ - 2
31
+ version: 0.5.2
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: thoughtbot-shoulda
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ description: A simple Ruby wrapper for the CloudApp API. Uses HTTParty with a simple ActiveResource-like interface.
47
+ email: aaron@gc4.co.uk
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - LICENSE
54
+ - README.md
55
+ files:
56
+ - .document
57
+ - .gitignore
58
+ - LICENSE
59
+ - README.md
60
+ - Rakefile
61
+ - VERSION
62
+ - cloudapp_api.gemspec
63
+ - lib/cloudapp/base.rb
64
+ - lib/cloudapp/client.rb
65
+ - lib/cloudapp/httparty.rb
66
+ - lib/cloudapp/monkey_patch/httparty.rb
67
+ - lib/cloudapp/monkey_patch/net_digest_auth.rb
68
+ - lib/cloudapp_api.rb
69
+ - test/helper.rb
70
+ - test/test_cloudly.rb
71
+ has_rdoc: true
72
+ homepage: http://github.com/aaronrussell/cloud_app
73
+ licenses: []
74
+
75
+ post_install_message:
76
+ rdoc_options:
77
+ - --charset=UTF-8
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ requirements: []
95
+
96
+ rubyforge_project:
97
+ rubygems_version: 1.3.6
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: A simple Ruby wrapper for the CloudApp API. Uses HTTParty with a simple ActiveResource-like interface.
101
+ test_files:
102
+ - test/helper.rb
103
+ - test/test_cloudly.rb