cloudpt-api 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +8 -0
- data/.rspec +1 -0
- data/Gemfile +10 -0
- data/LICENSE +22 -0
- data/README.markdown +322 -0
- data/Rakefile +4 -0
- data/cloudpt-api.gemspec +25 -0
- data/lib/cloudpt-api.rb +22 -0
- data/lib/cloudpt-api/client.rb +72 -0
- data/lib/cloudpt-api/client/files.rb +40 -0
- data/lib/cloudpt-api/client/raw.rb +52 -0
- data/lib/cloudpt-api/connection.rb +34 -0
- data/lib/cloudpt-api/connection/requests.rb +65 -0
- data/lib/cloudpt-api/objects/delta.rb +11 -0
- data/lib/cloudpt-api/objects/dir.rb +20 -0
- data/lib/cloudpt-api/objects/file.rb +44 -0
- data/lib/cloudpt-api/objects/fileops.rb +28 -0
- data/lib/cloudpt-api/objects/object.rb +39 -0
- data/lib/cloudpt-api/tasks.rb +48 -0
- data/lib/cloudpt-api/util/config.rb +27 -0
- data/lib/cloudpt-api/util/error.rb +16 -0
- data/lib/cloudpt-api/util/oauth.rb +29 -0
- data/lib/cloudpt-api/util/util.rb +27 -0
- data/lib/cloudpt-api/version.rb +5 -0
- data/spec/connection.sample.yml +5 -0
- data/spec/fixtures/cloudpt.jpg +0 -0
- data/spec/lib/cloudpt-api/client_spec.rb +208 -0
- data/spec/lib/cloudpt-api/connection_spec.rb +82 -0
- data/spec/lib/cloudpt-api/dir_spec.rb +44 -0
- data/spec/lib/cloudpt-api/file_spec.rb +126 -0
- data/spec/lib/cloudpt-api/oauth_spec.rb +17 -0
- data/spec/lib/cloudpt-api/thumbnail_spec.rb +29 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/support/config.rb +15 -0
- data/spec/support/jpeg.rb +39 -0
- metadata +139 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Cloudpt::API::OAuth do
|
|
4
|
+
|
|
5
|
+
describe ".consumer" do
|
|
6
|
+
|
|
7
|
+
it "raises an error if config options are not provided" do
|
|
8
|
+
Cloudpt::API::Config.stub!(:app_key).and_return(nil)
|
|
9
|
+
lambda {
|
|
10
|
+
Cloudpt::API::OAuth.consumer :main
|
|
11
|
+
}.should raise_error(Cloudpt::API::Error::Config)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
require "fileutils"
|
|
3
|
+
|
|
4
|
+
describe Cloudpt::API::File do
|
|
5
|
+
|
|
6
|
+
before do
|
|
7
|
+
@io = StringIO.new
|
|
8
|
+
@client = Cloudpt::Spec.instance
|
|
9
|
+
@filename = "#{Cloudpt::Spec.test_dir}/spec-test-#{Time.now.to_i}.jpg"
|
|
10
|
+
jpeg = File.read("spec/fixtures/cloudpt.jpg")
|
|
11
|
+
@file = @client.upload @filename, jpeg
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe "#thumbnail" do
|
|
15
|
+
|
|
16
|
+
it "downloads a thumbnail" do
|
|
17
|
+
result = @file.thumbnail
|
|
18
|
+
|
|
19
|
+
@io << result
|
|
20
|
+
@io.rewind
|
|
21
|
+
|
|
22
|
+
jpeg = JPEG.new(@io)
|
|
23
|
+
jpeg.height.should == 64
|
|
24
|
+
jpeg.width.should == 64
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
$:.push File.expand_path("../../lib", __FILE__)
|
|
2
|
+
|
|
3
|
+
require 'simplecov'
|
|
4
|
+
SimpleCov.start do
|
|
5
|
+
add_filter 'spec'
|
|
6
|
+
end
|
|
7
|
+
require 'cloudpt-api'
|
|
8
|
+
require 'rspec'
|
|
9
|
+
|
|
10
|
+
# If you wand to change the json, you can do it here
|
|
11
|
+
# I still believe yajl is the best :) - marcinbunsch
|
|
12
|
+
MultiJson.engine= :yajl
|
|
13
|
+
|
|
14
|
+
module Cloudpt
|
|
15
|
+
Spec = Hashie::Mash.new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
Dir.glob("#{File.dirname(__FILE__)}/support/*.rb").each { |f| require f }
|
|
19
|
+
|
|
20
|
+
# Clean up after specs, remove test-directory
|
|
21
|
+
RSpec.configure do |config|
|
|
22
|
+
config.after(:all) do
|
|
23
|
+
test_dir = Cloudpt::Spec.instance.find(Cloudpt::Spec.test_dir)
|
|
24
|
+
test_dir.destroy unless test_dir.is_deleted?
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require "yaml"
|
|
2
|
+
|
|
3
|
+
config = YAML.load_file "spec/connection.yml"
|
|
4
|
+
|
|
5
|
+
Cloudpt::API::Config.app_key = config['app_key']
|
|
6
|
+
Cloudpt::API::Config.app_secret = config['app_secret']
|
|
7
|
+
Cloudpt::API::Config.mode = config['mode']
|
|
8
|
+
|
|
9
|
+
Cloudpt::Spec.token = config['token']
|
|
10
|
+
Cloudpt::Spec.secret = config['secret']
|
|
11
|
+
|
|
12
|
+
Cloudpt::Spec.namespace = Time.now.to_i
|
|
13
|
+
Cloudpt::Spec.instance = Cloudpt::API::Client.new(:token => Cloudpt::Spec.token,
|
|
14
|
+
:secret => Cloudpt::Spec.secret)
|
|
15
|
+
Cloudpt::Spec.test_dir = "test-#{Time.now.to_i}"
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class JPEG
|
|
2
|
+
attr_reader :width, :height, :bits
|
|
3
|
+
|
|
4
|
+
def initialize(file)
|
|
5
|
+
examine(file)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
private
|
|
9
|
+
def examine(io)
|
|
10
|
+
raise 'malformed JPEG' unless io.getbyte == 0xFF && io.getbyte == 0xD8 # SOI
|
|
11
|
+
|
|
12
|
+
class << io
|
|
13
|
+
def readint; (getbyte << 8) + getbyte; end
|
|
14
|
+
def readframe; read(readint - 2); end
|
|
15
|
+
def readsof; [readint, getbyte, readint, readint, getbyte]; end
|
|
16
|
+
def next
|
|
17
|
+
c = getbyte while c != 0xFF
|
|
18
|
+
c = getbyte while c == 0xFF
|
|
19
|
+
c
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
while marker = io.next
|
|
24
|
+
case marker
|
|
25
|
+
when 0xC0..0xC3, 0xC5..0xC7, 0xC9..0xCB, 0xCD..0xCF # SOF markers
|
|
26
|
+
length, @bits, @height, @width, components = io.readsof
|
|
27
|
+
raise 'malformed JPEG' unless length == 8 + components * 3
|
|
28
|
+
when 0xD9, 0xDA
|
|
29
|
+
break # EOI, SOS
|
|
30
|
+
when 0xFE
|
|
31
|
+
@comment = io.readframe # COM
|
|
32
|
+
when 0xE1
|
|
33
|
+
io.readframe # APP1, contains EXIF tag
|
|
34
|
+
else
|
|
35
|
+
io.readframe # ignore frame
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: cloudpt-api
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Fabio Batista
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-02-25 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: multi_json
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: oauth
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
type: :runtime
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: hashie
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
none: false
|
|
50
|
+
requirements:
|
|
51
|
+
- - ! '>='
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
type: :runtime
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ! '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
description: To deliver a more Rubyesque experience when using the cloudpt API.
|
|
63
|
+
email:
|
|
64
|
+
- fbatista@webreakstuff.com
|
|
65
|
+
executables: []
|
|
66
|
+
extensions: []
|
|
67
|
+
extra_rdoc_files: []
|
|
68
|
+
files:
|
|
69
|
+
- .gitignore
|
|
70
|
+
- .rspec
|
|
71
|
+
- Gemfile
|
|
72
|
+
- LICENSE
|
|
73
|
+
- README.markdown
|
|
74
|
+
- Rakefile
|
|
75
|
+
- cloudpt-api.gemspec
|
|
76
|
+
- lib/cloudpt-api.rb
|
|
77
|
+
- lib/cloudpt-api/client.rb
|
|
78
|
+
- lib/cloudpt-api/client/files.rb
|
|
79
|
+
- lib/cloudpt-api/client/raw.rb
|
|
80
|
+
- lib/cloudpt-api/connection.rb
|
|
81
|
+
- lib/cloudpt-api/connection/requests.rb
|
|
82
|
+
- lib/cloudpt-api/objects/delta.rb
|
|
83
|
+
- lib/cloudpt-api/objects/dir.rb
|
|
84
|
+
- lib/cloudpt-api/objects/file.rb
|
|
85
|
+
- lib/cloudpt-api/objects/fileops.rb
|
|
86
|
+
- lib/cloudpt-api/objects/object.rb
|
|
87
|
+
- lib/cloudpt-api/tasks.rb
|
|
88
|
+
- lib/cloudpt-api/util/config.rb
|
|
89
|
+
- lib/cloudpt-api/util/error.rb
|
|
90
|
+
- lib/cloudpt-api/util/oauth.rb
|
|
91
|
+
- lib/cloudpt-api/util/util.rb
|
|
92
|
+
- lib/cloudpt-api/version.rb
|
|
93
|
+
- spec/connection.sample.yml
|
|
94
|
+
- spec/fixtures/cloudpt.jpg
|
|
95
|
+
- spec/lib/cloudpt-api/client_spec.rb
|
|
96
|
+
- spec/lib/cloudpt-api/connection_spec.rb
|
|
97
|
+
- spec/lib/cloudpt-api/dir_spec.rb
|
|
98
|
+
- spec/lib/cloudpt-api/file_spec.rb
|
|
99
|
+
- spec/lib/cloudpt-api/oauth_spec.rb
|
|
100
|
+
- spec/lib/cloudpt-api/thumbnail_spec.rb
|
|
101
|
+
- spec/spec_helper.rb
|
|
102
|
+
- spec/support/config.rb
|
|
103
|
+
- spec/support/jpeg.rb
|
|
104
|
+
homepage: http://github.com/fbatista/cloudpt-api
|
|
105
|
+
licenses: []
|
|
106
|
+
post_install_message:
|
|
107
|
+
rdoc_options: []
|
|
108
|
+
require_paths:
|
|
109
|
+
- lib
|
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
|
+
none: false
|
|
112
|
+
requirements:
|
|
113
|
+
- - ! '>='
|
|
114
|
+
- !ruby/object:Gem::Version
|
|
115
|
+
version: '0'
|
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
|
+
none: false
|
|
118
|
+
requirements:
|
|
119
|
+
- - ! '>='
|
|
120
|
+
- !ruby/object:Gem::Version
|
|
121
|
+
version: '0'
|
|
122
|
+
requirements: []
|
|
123
|
+
rubyforge_project: cloudpt-api
|
|
124
|
+
rubygems_version: 1.8.24
|
|
125
|
+
signing_key:
|
|
126
|
+
specification_version: 3
|
|
127
|
+
summary: A Ruby client for the cloudpt REST API.
|
|
128
|
+
test_files:
|
|
129
|
+
- spec/connection.sample.yml
|
|
130
|
+
- spec/fixtures/cloudpt.jpg
|
|
131
|
+
- spec/lib/cloudpt-api/client_spec.rb
|
|
132
|
+
- spec/lib/cloudpt-api/connection_spec.rb
|
|
133
|
+
- spec/lib/cloudpt-api/dir_spec.rb
|
|
134
|
+
- spec/lib/cloudpt-api/file_spec.rb
|
|
135
|
+
- spec/lib/cloudpt-api/oauth_spec.rb
|
|
136
|
+
- spec/lib/cloudpt-api/thumbnail_spec.rb
|
|
137
|
+
- spec/spec_helper.rb
|
|
138
|
+
- spec/support/config.rb
|
|
139
|
+
- spec/support/jpeg.rb
|