chute 0.0.2 → 2.0.0
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/Gemfile +16 -2
- data/Gemfile.lock +52 -0
- data/LICENSE.txt +20 -0
- data/README.md +46 -0
- data/Rakefile +48 -6
- data/VERSION +1 -0
- data/chute.gemspec +120 -16
- data/lib/chute.rb +7 -20
- data/lib/chute/client.rb +42 -0
- data/lib/chute/configuration.rb +40 -0
- data/lib/chute/connection.rb +64 -0
- data/lib/chute/response.rb +22 -0
- data/lib/chute/v2/albums.rb +60 -0
- data/lib/chute/v2/assets.rb +55 -0
- data/lib/chute/v2/comments.rb +29 -0
- data/lib/chute/v2/flags.rb +21 -0
- data/lib/chute/v2/hearts.rb +21 -0
- data/lib/chute/v2/parcels.rb +21 -0
- data/lib/chute/v2/tags.rb +36 -0
- data/lib/chute/v2/triggers.rb +26 -0
- data/lib/chute/v2/users.rb +18 -0
- data/lib/chute/v2/votes.rb +21 -0
- data/lib/chute/version.rb +7 -1
- data/spec/chute/chute_spec.rb +64 -0
- data/spec/chute/client_spec.rb +82 -0
- data/spec/chute/connection_spec.rb +47 -0
- data/spec/chute/response_spec.rb +16 -0
- data/spec/chute/v2/albums_spec.rb +197 -0
- data/spec/chute/v2/assets_spec.rb +171 -0
- data/spec/chute/v2/comments_spec.rb +88 -0
- data/spec/chute/v2/flags_spec.rb +56 -0
- data/spec/chute/v2/hearts_spec.rb +57 -0
- data/spec/chute/v2/parcels_spec.rb +24 -0
- data/spec/chute/v2/tags_spec.rb +79 -0
- data/spec/chute/v2/trigger_spec.rb +127 -0
- data/spec/chute/v2/users_spec.rb +53 -0
- data/spec/chute/v2/votes_spec.rb +56 -0
- data/spec/fixtures/chute_cassettes/albums/album_create_with_permission_view.yml +69 -0
- data/spec/fixtures/chute_cassettes/albums/albums_add_remove_assets.yml +187 -0
- data/spec/fixtures/chute_cassettes/albums/albums_create.yml +69 -0
- data/spec/fixtures/chute_cassettes/albums/albums_delete.yml +128 -0
- data/spec/fixtures/chute_cassettes/albums/albums_get.yml +135 -0
- data/spec/fixtures/chute_cassettes/albums/albums_list.yml +89 -0
- data/spec/fixtures/chute_cassettes/albums/albums_stats.yml +128 -0
- data/spec/fixtures/chute_cassettes/albums/albums_update.yml +135 -0
- data/spec/fixtures/chute_cassettes/assets/assets_delete.yml +131 -0
- data/spec/fixtures/chute_cassettes/assets/assets_geo.yml +197 -0
- data/spec/fixtures/chute_cassettes/assets/assets_get.yml +138 -0
- data/spec/fixtures/chute_cassettes/assets/assets_import.yml +76 -0
- data/spec/fixtures/chute_cassettes/assets/assets_list.yml +77 -0
- data/spec/fixtures/chute_cassettes/assets/assets_update.yml +138 -0
- data/spec/fixtures/chute_cassettes/comments/comments_create.yml +196 -0
- data/spec/fixtures/chute_cassettes/comments/comments_list.yml +259 -0
- data/spec/fixtures/chute_cassettes/flags/flags_methods.yml +313 -0
- data/spec/fixtures/chute_cassettes/hearts/hearts_methods.yml +254 -0
- data/spec/fixtures/chute_cassettes/tags/tags_assets.yml +311 -0
- data/spec/fixtures/chute_cassettes/triggers/trigger_errors.yml +62 -0
- data/spec/fixtures/chute_cassettes/triggers/triggers_cleanup.yml +184 -0
- data/spec/fixtures/chute_cassettes/triggers/triggers_create.yml +65 -0
- data/spec/fixtures/chute_cassettes/triggers/triggers_delete.yml +124 -0
- data/spec/fixtures/chute_cassettes/triggers/triggers_list.yml +66 -0
- data/spec/fixtures/chute_cassettes/triggers/triggers_update.yml +127 -0
- data/spec/fixtures/chute_cassettes/users/users_get.yml +128 -0
- data/spec/fixtures/chute_cassettes/users/users_me.yml +66 -0
- data/spec/fixtures/chute_cassettes/votes/votes_methods.yml +313 -0
- data/spec/spec_helper.rb +27 -0
- metadata +210 -33
- data/.gitignore +0 -5
- data/README +0 -125
- data/config/chute.rb +0 -0
- data/lib/chute/account.rb +0 -58
- data/lib/chute/app.rb +0 -32
- data/lib/chute/asset.rb +0 -124
- data/lib/chute/bundle.rb +0 -72
- data/lib/chute/chute.rb +0 -203
- data/lib/chute/collection.rb +0 -47
- data/lib/chute/comment.rb +0 -32
- data/lib/chute/exception.rb +0 -7
- data/lib/chute/http_service.rb +0 -114
- data/lib/chute/inbox.rb +0 -41
- data/lib/chute/parcel.rb +0 -45
- data/lib/chute/resource.rb +0 -354
- data/lib/chute/user.rb +0 -113
- data/lib/chute/util.rb +0 -14
- data/test/test_sudoku.rb +0 -7
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
require 'hashie/mash'
|
4
|
+
|
5
|
+
module Chute
|
6
|
+
class Connection
|
7
|
+
include HTTParty
|
8
|
+
format :json
|
9
|
+
|
10
|
+
def self.base_uri
|
11
|
+
Chute.api_endpoint
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.headers
|
15
|
+
{
|
16
|
+
'Authorization' => "OAuth #{Chute.access_token}",
|
17
|
+
'Content-Type' => 'application/json',
|
18
|
+
'Accepts' => 'application/json',
|
19
|
+
'x-client_id' => Chute.app_id
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.request(request_type, url, body="")
|
24
|
+
body = body.to_json unless String === body
|
25
|
+
options = body.empty? ? {:headers => headers} : {:headers => headers, :body => body}
|
26
|
+
begin
|
27
|
+
response = self.send(request_type, "#{base_uri}#{url}", options)
|
28
|
+
=begin
|
29
|
+
|
30
|
+
puts "----------------------------------------"
|
31
|
+
puts "Requesting url: #{base_uri}#{url}"
|
32
|
+
puts response.parsed_response
|
33
|
+
puts "----------------------------------------"
|
34
|
+
=end
|
35
|
+
|
36
|
+
parse(response)
|
37
|
+
rescue Errno::ECONNREFUSED
|
38
|
+
p 'Service Unavailable'
|
39
|
+
Chute::Response.with_code_and_error(503, 'Service Unavailable')
|
40
|
+
raise ChuteApiUnavailableException.new('Could not connect to the Server')
|
41
|
+
rescue MultiJson::DecodeError
|
42
|
+
p 'Internal Server Error'
|
43
|
+
Chute::Response.with_code_and_error(500, 'Internal Server Error')
|
44
|
+
raise ChuteApiInternalException.new('Chute API Exception')
|
45
|
+
rescue Exception => ex
|
46
|
+
p 'Unknown Error'
|
47
|
+
raise
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.parse(object)
|
52
|
+
if object.respond_to?(:each_pair)
|
53
|
+
Chute::Response.new(object)
|
54
|
+
else
|
55
|
+
[200, 201].include?(object.code)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class ChuteApiUnavailableException < Exception;
|
61
|
+
end
|
62
|
+
class ChuteApiInternalException < Exception;
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'hashie/mash'
|
2
|
+
|
3
|
+
module Chute
|
4
|
+
class Response < Hashie::Mash
|
5
|
+
|
6
|
+
def self.with_code_and_error(code, error)
|
7
|
+
object = Chute::Response.new
|
8
|
+
object.code = code
|
9
|
+
object.errors = [error]
|
10
|
+
object
|
11
|
+
end
|
12
|
+
|
13
|
+
def success?
|
14
|
+
[200, 201].include?(response.code)
|
15
|
+
end
|
16
|
+
|
17
|
+
def pretty_print
|
18
|
+
puts JSON.pretty_generate self
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Chute
|
2
|
+
module V2
|
3
|
+
class Albums
|
4
|
+
class << self
|
5
|
+
# Album Listing
|
6
|
+
def all(page=nil, per_page=nil)
|
7
|
+
Chute::Client.get("/v2/albums", :page=> page, :per_page=> per_page)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Album Details
|
11
|
+
def find(id)
|
12
|
+
Chute::Client.get("/v2/albums/#{id}")
|
13
|
+
end
|
14
|
+
|
15
|
+
# Album Assets Geo Search
|
16
|
+
def geo_locate(id, lat, lng, radius)
|
17
|
+
Chute::Client.get("/v2/albums/#{id}/assets/geo/#{lat},#{lng}/#{radius}")
|
18
|
+
end
|
19
|
+
|
20
|
+
# Album Assets
|
21
|
+
def assets(id, page, per_page)
|
22
|
+
Chute::Client.get("/v2/albums/#{id}/assets", :page=> page, :per_page=> per_page)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Import Album Assets
|
26
|
+
def import(album_id, *urls)
|
27
|
+
Chute::Client.post("/v2/albums/#{album_id}/assets/import", :urls=> urls)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Album Create
|
31
|
+
def create(album)
|
32
|
+
Chute::Client.post("/v2/albums", :album => album)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Album Update
|
36
|
+
def update(id, album={})
|
37
|
+
Chute::Client.put("/v2/albums/#{id}", :album => album)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Album Delete
|
41
|
+
def delete(id)
|
42
|
+
Chute::Client.delete("/v2/albums/#{id}")
|
43
|
+
end
|
44
|
+
|
45
|
+
def stats(album_id)
|
46
|
+
Chute::Client.get("/v2/albums/#{album_id}/stats")
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_assets(album_id, *asset_ids)
|
50
|
+
Chute::Client.post("/v2/albums/#{album_id}/add_assets", :asset_ids => asset_ids)
|
51
|
+
end
|
52
|
+
|
53
|
+
def remove_assets(album_id, *asset_ids)
|
54
|
+
Chute::Client.post("/v2/albums/#{album_id}/remove_assets",:asset_ids => asset_ids)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Chute
|
2
|
+
module V2
|
3
|
+
class Assets
|
4
|
+
class << self
|
5
|
+
# Asset Listing
|
6
|
+
def all(album_id)
|
7
|
+
Chute::Client.get("/v2/albums/#{album_id}/assets")
|
8
|
+
end
|
9
|
+
|
10
|
+
# Asset Details
|
11
|
+
def find(id)
|
12
|
+
Chute::Client.get("/v2/assets/#{id}")
|
13
|
+
end
|
14
|
+
|
15
|
+
# Asset Geo Locate
|
16
|
+
def geo_locate(lat, lng, radius)
|
17
|
+
Chute::Client.get("/v2/assets/geo/#{lat},#{lng}/#{radius}")
|
18
|
+
end
|
19
|
+
|
20
|
+
# Asset Exif
|
21
|
+
def exif(id)
|
22
|
+
Chute::Client.get("/v2/assets/#{id}/exif")
|
23
|
+
end
|
24
|
+
|
25
|
+
# Asset Geo
|
26
|
+
def geo(id)
|
27
|
+
Chute::Client.get("/v2/assets/#{id}/geo")
|
28
|
+
end
|
29
|
+
|
30
|
+
# TODO Implement on server: Asset Create
|
31
|
+
def upload(data)
|
32
|
+
Chute::Client.post("/v2/assets/upload", :urls => urls)
|
33
|
+
end
|
34
|
+
|
35
|
+
def import(urls, shortcuts)
|
36
|
+
params = Hash.new
|
37
|
+
params[:urls] = urls unless urls==nil
|
38
|
+
params[:shortcuts] = shortcuts unless shortcuts==nil
|
39
|
+
Chute::Client.post("/v2/assets/import", params)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Asset Update
|
43
|
+
# Title
|
44
|
+
def update(id, asset={})
|
45
|
+
Chute::Client.put("/v2/assets/#{id}", asset)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Album Delete
|
49
|
+
def delete(id)
|
50
|
+
Chute::Client.delete("/v2/assets/#{id}")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Chute
|
2
|
+
module V2
|
3
|
+
class Comments
|
4
|
+
class << self
|
5
|
+
|
6
|
+
# Assets Comments
|
7
|
+
def all(album_id, asset_id)
|
8
|
+
Chute::Client.get("/v2/albums/#{album_id}/assets/#{asset_id}/comments")
|
9
|
+
end
|
10
|
+
|
11
|
+
# Comment params
|
12
|
+
# Params
|
13
|
+
# comment_text
|
14
|
+
# name
|
15
|
+
# email
|
16
|
+
def create(album_id, asset_id, comment={})
|
17
|
+
Chute::Client.post("/v2/albums/#{album_id}/assets/#{asset_id}/comments", comment)
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def delete(comment_id)
|
22
|
+
Chute::Client.delete("/v2/comments/#{comment_id}")
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Chute
|
2
|
+
module V2
|
3
|
+
class Flags
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def count(album_id, asset_id)
|
7
|
+
Chute::Client.get("/v2/albums/#{album_id}/assets/#{asset_id}/flags")
|
8
|
+
end
|
9
|
+
|
10
|
+
def flag(album_id, asset_id)
|
11
|
+
Chute::Client.post("/v2/albums/#{album_id}/assets/#{asset_id}/flags")
|
12
|
+
end
|
13
|
+
|
14
|
+
def unflag(album_id, asset_id)
|
15
|
+
Chute::Client.delete("/v2/albums/#{album_id}/assets/#{asset_id}/flags")
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Chute
|
2
|
+
module V2
|
3
|
+
class Hearts
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def count(album_id, asset_id)
|
7
|
+
Chute::Client.get("/v2/albums/#{album_id}/assets/#{asset_id}/hearts")
|
8
|
+
end
|
9
|
+
|
10
|
+
def heart(album_id, asset_id)
|
11
|
+
Chute::Client.post("/v2/albums/#{album_id}/assets/#{asset_id}/hearts")
|
12
|
+
end
|
13
|
+
|
14
|
+
def unheart(album_id, asset_id, id)
|
15
|
+
Chute::Client.delete("/v2/albums/#{album_id}/assets/#{asset_id}/hearts/#{id}")
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Chute
|
2
|
+
module V2
|
3
|
+
class Parcels
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def all_parcel_assets(parcel_id)
|
7
|
+
Chute::Client.get("/v2/parcels/#{parcel_id}/assets")
|
8
|
+
end
|
9
|
+
|
10
|
+
def find(id)
|
11
|
+
Chute::Client.get("/v2/parcels/#{id}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def all_album_parcels(album_id)
|
15
|
+
Chute::Client.get("/v2/albums/#{album_id}/parcels")
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Chute
|
2
|
+
module V2
|
3
|
+
class Tags
|
4
|
+
class << self
|
5
|
+
|
6
|
+
# Asset Tags
|
7
|
+
def all_asset_tags(album_id, asset_id)
|
8
|
+
Chute::Client.get("/v2/albums/#{album_id}/assets/#{asset_id}/tags")
|
9
|
+
end
|
10
|
+
|
11
|
+
# Change the complete list of tags for an asset inside an album
|
12
|
+
def update_asset_tags(album_id, asset_id, *tags)
|
13
|
+
Chute::Client.put("/v2/albums/#{album_id}/assets/#{asset_id}/tags", :tags => process_array(tags))
|
14
|
+
end
|
15
|
+
|
16
|
+
# Add new tags to existing assets, without replacing the current ones
|
17
|
+
def add_asset_tags(album_id, asset_id, *tags)
|
18
|
+
Chute::Client.post("/v2/albums/#{album_id}/assets/#{asset_id}/tags", :tags => process_array(tags))
|
19
|
+
end
|
20
|
+
|
21
|
+
# Delete all tags from an asset
|
22
|
+
def delete_asset_tags(album_id, asset_id, *tags)
|
23
|
+
Chute::Client.delete("/v2/albums/#{album_id}/assets/#{asset_id}/tags", :tags => process_array(tags))
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def process_array(*args)
|
29
|
+
args.flatten.uniq
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Chute
|
2
|
+
module V2
|
3
|
+
class Triggers
|
4
|
+
class << self
|
5
|
+
|
6
|
+
# Asset Tags
|
7
|
+
def all
|
8
|
+
Chute::Client.get("/v2/triggers")
|
9
|
+
end
|
10
|
+
|
11
|
+
def create(url, event)
|
12
|
+
Chute::Client.post("/v2/triggers", :url => url, :event => event)
|
13
|
+
end
|
14
|
+
|
15
|
+
def update(trigger_id,url, event)
|
16
|
+
Chute::Client.put("/v2/triggers/#{trigger_id}", :url => url, :event => event)
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete(trigger_id)
|
20
|
+
Chute::Client.delete("/v2/triggers/#{trigger_id}")
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Chute
|
2
|
+
module V2
|
3
|
+
class Votes
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def count(album_id, asset_id)
|
7
|
+
Chute::Client.get("/v2/albums/#{album_id}/assets/#{asset_id}/votes")
|
8
|
+
end
|
9
|
+
|
10
|
+
def vote(album_id, asset_id)
|
11
|
+
Chute::Client.post("/v2/albums/#{album_id}/assets/#{asset_id}/votes")
|
12
|
+
end
|
13
|
+
|
14
|
+
def remove_vote(album_id, asset_id)
|
15
|
+
Chute::Client.delete("/v2/albums/#{album_id}/assets/#{asset_id}/votes")
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/chute/version.rb
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chute do
|
4
|
+
|
5
|
+
# test/awesome/configuration_test.rbrequire 'helper'
|
6
|
+
|
7
|
+
describe 'configuration' do
|
8
|
+
|
9
|
+
describe '.api_endpoint' do
|
10
|
+
it 'should return default api_endpoint' do
|
11
|
+
Chute.api_endpoint.should == Chute::Configuration::DEFAULT_API_ENDPOINT
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.auth_endpoint' do
|
16
|
+
it 'should return default auth_endpoint' do
|
17
|
+
Chute.auth_endpoint.should == Chute::Configuration::DEFAULT_AUTH_ENDPOINT
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.app_id' do
|
22
|
+
it 'should return default app_id' do
|
23
|
+
Chute.app_id.should == Chute::Configuration::DEFAULT_APP_ID
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '.app_secret' do
|
28
|
+
it 'should return default app_secret' do
|
29
|
+
Chute.app_secret.should == Chute::Configuration::DEFAULT_APP_SECRET
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '.access_token' do
|
34
|
+
it 'should return default access_token' do
|
35
|
+
Chute.access_token.should == Chute::Configuration::DEFAULT_ACCESS_TOKEN
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
after do
|
40
|
+
Chute.reset
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '.configure' do
|
44
|
+
Chute::Configuration::VALID_CONFIG_KEYS.each do |key|
|
45
|
+
it "should set the #{key}" do
|
46
|
+
Chute.configure do |config|
|
47
|
+
config.send("#{key}=", key)
|
48
|
+
Chute.send(key).should == key
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
Chute::Configuration::VALID_CONFIG_KEYS.each do |key|
|
55
|
+
describe ".#{key}" do
|
56
|
+
it 'should return the default value' do
|
57
|
+
Chute.send(key).should == Chute::Configuration.const_get("DEFAULT_#{key.upcase}")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|