atlas-api 0.0.4 → 0.0.5

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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- atlas-api (0.0.3)
4
+ atlas-api (0.0.4)
5
5
  faraday (~> 0.5.3)
6
6
  hashie (~> 0.4.0)
7
7
 
@@ -16,7 +16,6 @@ GEM
16
16
  addressable (~> 2.2.4)
17
17
  multipart-post (~> 1.1.0)
18
18
  rack (>= 1.1.0, < 2)
19
- rack (>= 1.1.0, < 2)
20
19
  hashie (0.4.0)
21
20
  multipart-post (1.1.5)
22
21
  rack (1.5.2)
@@ -26,9 +25,9 @@ GEM
26
25
  rspec-expectations (~> 2.14.0)
27
26
  rspec-mocks (~> 2.14.0)
28
27
  rspec-core (2.14.4)
29
- rspec-expectations (2.14.0)
28
+ rspec-expectations (2.14.1)
30
29
  diff-lcs (>= 1.1.3, < 2.0)
31
- rspec-mocks (2.14.2)
30
+ rspec-mocks (2.14.3)
32
31
  safe_yaml (0.9.5)
33
32
  webmock (1.13.0)
34
33
  addressable (>= 2.2.7)
data/README.md CHANGED
@@ -1,3 +1,25 @@
1
1
  # Atlas::Api
2
2
 
3
- Gem to interact with the O'Reilly Media Atlas API. See tests for coverage.
3
+ Gem to interact with the O'Reilly Media Atlas API.
4
+
5
+ ## Installing
6
+
7
+ Install this gem by running:
8
+
9
+ ```bash
10
+ $ gem install atlas-api
11
+ ```
12
+
13
+ ## Command Line Script
14
+
15
+ You can build a specific project by calling the `atlas build` command line:
16
+
17
+ ```bash
18
+ $ atlas build ATLAS_TOKEN PROJECT FORMATS BRANCH
19
+ ```
20
+
21
+ A real world example of this would look something like this:
22
+
23
+ ```bash
24
+ $ atlas build abcdefg oreillymedia/atlas_book_skeleton pdf,epub,html master
25
+ ```
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require 'rubygems'
5
+ require 'atlas-api'
6
+
7
+ ENDPOINT = "http://orm-atlas.herokuapp.com/api"
8
+
9
+ raise Exception unless ARGV[0] == "build"
10
+
11
+ TOKEN = ARGV[1]
12
+ PROJECT = ARGV[2]
13
+ FORMATS = ARGV[3]
14
+ BRANCH = ARGV[4] || "master"
15
+
16
+ puts "Building ..."
17
+
18
+ # Run Script
19
+ # --------------------------------------------------------
20
+
21
+ client = Atlas::Api::Client.new(
22
+ auth_token: TOKEN,
23
+ api_endpoint: ENDPOINT
24
+ )
25
+
26
+ query = {
27
+ :project => PROJECT,
28
+ :formats => FORMATS,
29
+ :branch => BRANCH
30
+ }
31
+
32
+ @last_response = client.build_and_poll(query)
33
+
34
+ @last_response.status.each do |format|
35
+ puts "#{format.format.upcase} Build Info"
36
+ puts "--------------------------------------------------"
37
+
38
+ if format.message.is_a?(Hash)
39
+ format.message.each do |k,v|
40
+ puts "#{k}".capitalize
41
+ v.each do |me|
42
+ puts "- #{me}"
43
+ end
44
+ end
45
+ else
46
+ puts "#{format.message}"
47
+ end
48
+
49
+ puts ""
50
+ end
51
+
52
+ puts "Download Formats"
53
+ puts "--------------------------------------------------"
54
+ @last_response.status.each do |format|
55
+ puts "#{format.format.upcase}: #{format.download_url}"
56
+ end
@@ -14,6 +14,23 @@ module Atlas
14
14
  # Builds
15
15
  # ------------------------------------------------------------------------
16
16
 
17
+ def build_and_poll(query)
18
+ post_response = create_build(query)
19
+ tries = 0
20
+
21
+ while(true)
22
+ last_response = build(post_response.id)
23
+ break if last_response.status.find { |format| format.status == "queued" || format.status == "working" }.nil?
24
+ tries += 1
25
+ if tries > 20
26
+ raise "The build is taking too long. Exiting"
27
+ end
28
+ sleep(5)
29
+ end
30
+
31
+ last_response
32
+ end
33
+
17
34
  def builds(options = {})
18
35
  get("builds", options)
19
36
  end
@@ -1,5 +1,5 @@
1
1
  module Atlas
2
2
  module Api
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -46,6 +46,71 @@ describe Atlas::Api::Client do
46
46
 
47
47
  describe "Builds" do
48
48
 
49
+ describe "#build_and_poll" do
50
+
51
+ it "polls the api until all builds are done" do
52
+ @client.stub(:sleep).and_return(true)
53
+
54
+ query = {
55
+ :project => "atlasservers/basic-sample",
56
+ :formats => "pdf,html",
57
+ :branch => "master",
58
+ :pingback_url => "http://www.someurl.com"
59
+ }
60
+
61
+ first = {
62
+ "id" => 1,
63
+ "status" => [
64
+ {
65
+ "format" => "pdf",
66
+ "status" => "queued"
67
+ },
68
+ {
69
+ "format" => "html",
70
+ "status" => "queued"
71
+ }
72
+ ]
73
+ }
74
+
75
+ second = {
76
+ "id" => 1,
77
+ "status" => [
78
+ {
79
+ "format" => "pdf",
80
+ "status" => "completed",
81
+ "download_url" => "pdfurl"
82
+ },
83
+ {
84
+ "format" => "html",
85
+ "status" => "queued"
86
+ }
87
+ ]
88
+ }
89
+
90
+ third = {
91
+ "id" => 1,
92
+ "status" => [
93
+ {
94
+ "format" => "pdf",
95
+ "status" => "completed",
96
+ "download_url" => "pdfurl"
97
+ },
98
+ {
99
+ "format" => "html",
100
+ "status" => "failed",
101
+ "message" => "wrong"
102
+ }
103
+ ]
104
+ }
105
+
106
+ stub_request_with_token(:post, "builds", first.to_json, query)
107
+ stub_request_with_token(:get, "builds/1", second.to_json).then.to_return(:body => third.to_json)
108
+ res = @client.build_and_poll(query)
109
+ res["status"].first["status"].should == "completed"
110
+ res["status"].last["status"].should == "failed"
111
+ end
112
+ end
113
+
49
114
  it "#create_build" do
50
115
  query = {
51
116
  :project => "atlasservers/basic-sample",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atlas-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-12 00:00:00.000000000 Z
12
+ date: 2013-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -78,7 +78,8 @@ dependencies:
78
78
  description: Gem to interact with the O'Reilly Media Atlas API
79
79
  email:
80
80
  - rune@runemadsen.com
81
- executables: []
81
+ executables:
82
+ - atlas
82
83
  extensions: []
83
84
  extra_rdoc_files: []
84
85
  files:
@@ -92,6 +93,7 @@ files:
92
93
  - README.md
93
94
  - Rakefile
94
95
  - atlas-api.gemspec
96
+ - bin/atlas
95
97
  - lib/atlas-api.rb
96
98
  - lib/atlas-api/client.rb
97
99
  - lib/atlas-api/version.rb