jackie 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .ruby-version
19
+ test_root
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - rbx
7
+ branches:
8
+ only:
9
+ - master
10
+ matrix:
11
+ include:
12
+ - rvm: jruby
13
+ env: JRUBY_OPTS="--1.9 --server -Xcext.enabled=true"
14
+ - rvm: jruby-head
15
+ env: JRUBY_OPTS="--1.9 --server -Xcext.enabled=true"
16
+ before_script:
17
+ - rake fake_s3
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in jackie.gemspec
4
4
  gemspec
5
+ gem 'aws-s3'
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/firebaseco/jackie.png?branch=master)](https://travis-ci.org/firebaseco/jackie)
2
+
1
3
  # Jackie
2
4
 
3
5
  A Ruby interface to the Kickfolio API.
@@ -25,37 +27,52 @@ Or install it yourself as:
25
27
  ```
26
28
  ### Basic Objects Operations
27
29
  ```ruby
28
- # Create New app
29
- app = Jackie::App.new(app_attributes)
30
+ # Create a new app
31
+ app = Jackie::App.new(:name => "Hello")
30
32
  app.save
31
33
 
32
- # Find the app with app_id 1.
34
+ # Find the app with id 1.
33
35
  app = Jackie::App.find(1)
34
- app.name = "new name"
36
+ app.name = "HelloWorld"
35
37
  app.save
36
38
 
37
- # GET the App versions
38
- app.versions
39
-
40
- # Delete a App
39
+ # Delete an App
41
40
  app.destroy
42
41
 
43
- # GET the Apps
42
+ # Get all the existing Apps
44
43
  Jackie::App.all
45
44
 
46
- # Create New App Version
47
- version = Jackie::Version.new(:app_id => app.id, :bundle_url => "https://bundle_url.com/myiosapp")
45
+ # Create a new Version of an App
46
+ version = Jackie::Version.new(:app_id => app.id, :bundle_url => "https://site.org/hello.app.zip")
48
47
  version.save
49
48
 
50
- # Find the version with version id 1.
49
+ # Find the version with id 1.
51
50
  version = Jackie::Version.find(1)
52
51
 
53
- # GET All Versions
52
+ # Get all the Versions
54
53
  Jackie::Version.all
55
54
 
55
+ # GET all the Versions of an App
56
+ app.versions
57
+
56
58
  # Delete a Version
57
59
  version.destroy
58
60
  ```
61
+ ### Jackie and AWS-S3
62
+ The following is optional. You can use Jackie without S3 as seem above.
63
+ ```ruby
64
+ # Set your AWS api keys
65
+ Jackie.configure_s3({
66
+ :access_key_id => "YOUR ACCESS KEY ID",
67
+ :secret_access_key => "YOUR SECRET ACCESS KEY"
68
+ }, {:bucket => "YOUR BUCKET"})
69
+
70
+ # Usage
71
+ version = Jackie::Version.new(:app_id => app.id, :file => "path/to/local/file.zip")
72
+ version.save
73
+ ```
74
+ For additional information read the [Kickfolio API docs](https://github.com/Kickfolio/ApiDocs)
75
+
59
76
  ## Contributing
60
77
 
61
78
  1. Fork it
@@ -68,4 +85,4 @@ License
68
85
  -------
69
86
 
70
87
  Jackie is Copyright © 2013 Firebase. It is free software,
71
- and may be redistributed under the terms specified in the MIT-LICENSE file.
88
+ and may be redistributed under the terms specified in the LICENSE.txt file.
data/Rakefile CHANGED
@@ -13,6 +13,10 @@ task :help do
13
13
  puts "rake test - Run tests"
14
14
  end
15
15
 
16
+ task :fake_s3 do
17
+ system "fakes3 --port 10453 --root test_root &"
18
+ end
19
+
16
20
  task :test do
17
21
  Dir.chdir('test')
18
22
  end
@@ -1,11 +1,8 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'jackie'
5
2
 
6
3
  Gem::Specification.new do |spec|
7
4
  spec.name = "jackie"
8
- spec.version = Jackie::VERSION
5
+ spec.version = "0.0.3"
9
6
  spec.authors = ["Lacides Charris", "Guillermo Iguaran", "Roberto Miranda", "Firebase.co"]
10
7
  spec.email = ["lacides@firebase.co", "guille@firebase.co", "roberto@firebase.co", "hello@firebase.co"]
11
8
  spec.description = %q{A Ruby interface to the Kickfolio API.}
@@ -20,6 +17,7 @@ Gem::Specification.new do |spec|
20
17
 
21
18
  spec.add_development_dependency "rake"
22
19
  spec.add_development_dependency "minitest"
20
+ spec.add_development_dependency "fakes3"
23
21
 
24
- spec.add_dependency "activeresource"
22
+ spec.add_dependency "activeresource", "~> 3.2.13"
25
23
  end
@@ -3,11 +3,16 @@ require "active_resource"
3
3
  require "jackie/base"
4
4
  require "jackie/app"
5
5
  require "jackie/version"
6
+ require "jackie/aws_uploader"
6
7
 
7
8
  module Jackie
8
- VERSION = "0.0.2"
9
-
10
9
  def self.api_key=(api_key)
11
10
  Jackie::Base.api_key = api_key
12
11
  end
12
+
13
+ # So, it should be straightforward to add support for ftp or dropbox or whatever.
14
+ # By creating a uploader (with the public api of AWSUploader) and calling set_uploader with it
15
+ def self.configure_s3(connection_params, access_params)
16
+ Jackie::Version.set_uploader(Jackie::AWSUploader.new(connection_params, access_params))
17
+ end
13
18
  end
@@ -0,0 +1,24 @@
1
+ module Jackie
2
+ class AWSUploader
3
+ def initialize(connection_params, access_params)
4
+ load_dependency
5
+ AWS::S3::Base.establish_connection!(connection_params)
6
+ @config = access_params
7
+ end
8
+
9
+ def upload(file)
10
+ AWS::S3::S3Object.store(file, open(file), @config[:bucket])
11
+ AWS::S3::S3Object.url_for(file, @config[:bucket])
12
+ end
13
+
14
+ private
15
+ def load_dependency
16
+ begin
17
+ require "aws/s3"
18
+ rescue LoadError => e
19
+ $stderr.puts "You don't have aws/s3 installed in your application. Please add it to your Gemfile and run bundle install"
20
+ raise e
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,7 +1,20 @@
1
1
  module Jackie
2
2
  class Version < Base
3
+ cattr_accessor :uploader, :instance_writer => false
4
+
5
+ class << self
6
+ def set_uploader(uploader)
7
+ self.uploader = uploader
8
+ end
9
+ end
10
+
3
11
  def preview_url
4
12
  "http://kickfolio.com/v/#{app_id}/version/#{id}"
5
13
  end
14
+
15
+ def save
16
+ self.bundle_url = uploader.upload(attributes["file"]) if attributes["file"] && uploader
17
+ super
18
+ end
6
19
  end
7
- end
20
+ end
@@ -11,6 +11,6 @@ class AppTest < MiniTest::Unit::TestCase
11
11
  end
12
12
 
13
13
  def test_versions
14
- assert_kind_of ActiveResource::Collection, @app.versions
14
+ assert_kind_of Jackie::Version, @app.versions.first
15
15
  end
16
16
  end
@@ -12,6 +12,20 @@ require "minitest/autorun"
12
12
  Jackie.api_key = "MyKickfolioApiKey"
13
13
 
14
14
  class MiniTest::Unit::TestCase
15
+ def with_fake_s3
16
+ Jackie.configure_s3({
17
+ :access_key_id => "123",
18
+ :secret_access_key => "abc",
19
+ :server => "localhost",
20
+ :port => "10453"
21
+ }, {:bucket => "nuvado-test"})
22
+
23
+ yield
24
+ ensure
25
+ AWS::S3::Base.disconnect!
26
+ Jackie::Version.uploader = nil
27
+ end
28
+
15
29
  def self.mock_requests!
16
30
  # FIXME move to fixture module
17
31
  @app = { "id" => "1",
@@ -45,6 +59,7 @@ class MiniTest::Unit::TestCase
45
59
  mock.get "/api/apps/1.json", @headers, @app
46
60
  mock.get "/api/versions.json?app_id=1", @headers, [@version].to_json
47
61
  mock.get "/api/versions/1.json", @headers, @version.to_json
62
+ mock.post "/api/versions.json", @headers
48
63
  end
49
64
  end
50
65
  end
@@ -10,4 +10,30 @@ class VersionTest < MiniTest::Unit::TestCase
10
10
  assert_match @version.app_id, @version.preview_url
11
11
  assert_match @version.id, @version.preview_url
12
12
  end
13
+
14
+ def test_save_new_with_file
15
+ with_fake_s3 do
16
+ version = Jackie::Version.new(:app_id => 1, :file => File.basename(__FILE__))
17
+ version.save
18
+ assert_match /http:\/\/localhost:10453\/nuvado-test\/version_test\.rb/, version.bundle_url
19
+ end
20
+ end
21
+
22
+ def test_create_with_file
23
+ with_fake_s3 do
24
+ version = Jackie::Version.create(:app_id => 1, :file => File.basename(__FILE__))
25
+ assert_match /http:\/\/localhost:10453\/nuvado-test\/version_test\.rb/, version.bundle_url
26
+ end
27
+ end
28
+
29
+ def test_save_new_with_bundle_url
30
+ version = Jackie::Version.new(:app_id => 1, :bundle_url => "http://somewhere.in/the/cloud")
31
+ version.save
32
+ assert_equal "http://somewhere.in/the/cloud", version.bundle_url
33
+ end
34
+
35
+ def test_create_with_bundle_url
36
+ version = Jackie::Version.create(:app_id => 1, :bundle_url => "http://somewhere.in/the/cloud")
37
+ assert_equal "http://somewhere.in/the/cloud", version.bundle_url
38
+ end
13
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jackie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-03-16 00:00:00.000000000 Z
15
+ date: 2013-03-19 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rake
@@ -47,14 +47,14 @@ dependencies:
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  - !ruby/object:Gem::Dependency
50
- name: activeresource
50
+ name: fakes3
51
51
  requirement: !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ! '>='
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
- type: :runtime
57
+ type: :development
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
60
60
  none: false
@@ -62,6 +62,22 @@ dependencies:
62
62
  - - ! '>='
63
63
  - !ruby/object:Gem::Version
64
64
  version: '0'
65
+ - !ruby/object:Gem::Dependency
66
+ name: activeresource
67
+ requirement: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ version: 3.2.13
73
+ type: :runtime
74
+ prerelease: false
75
+ version_requirements: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ~>
79
+ - !ruby/object:Gem::Version
80
+ version: 3.2.13
65
81
  description: A Ruby interface to the Kickfolio API.
66
82
  email:
67
83
  - lacides@firebase.co
@@ -73,6 +89,7 @@ extensions: []
73
89
  extra_rdoc_files: []
74
90
  files:
75
91
  - .gitignore
92
+ - .travis.yml
76
93
  - Gemfile
77
94
  - LICENSE.txt
78
95
  - README.md
@@ -80,6 +97,7 @@ files:
80
97
  - jackie.gemspec
81
98
  - lib/jackie.rb
82
99
  - lib/jackie/app.rb
100
+ - lib/jackie/aws_uploader.rb
83
101
  - lib/jackie/base.rb
84
102
  - lib/jackie/version.rb
85
103
  - test/app_test.rb