trip_advisor 0.0.15

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.
Files changed (115) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitignore +52 -0
  4. data/.rspec +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +5 -0
  7. data/Gemfile +4 -0
  8. data/Gemfile.lock +118 -0
  9. data/LICENSE.txt +20 -0
  10. data/README.md +23 -0
  11. data/Rakefile +7 -0
  12. data/lib/trip_advisor/api.rb +45 -0
  13. data/lib/trip_advisor/build.rb +221 -0
  14. data/lib/trip_advisor/rake_tasks.rb +182 -0
  15. data/lib/trip_advisor/resource_manager.rb +101 -0
  16. data/lib/trip_advisor/strings_file.rb +112 -0
  17. data/lib/trip_advisor/translation.rb +63 -0
  18. data/lib/trip_advisor/translation_tool.rb +110 -0
  19. data/lib/trip_advisor/version.rb +3 -0
  20. data/lib/trip_advisor.rb +5 -0
  21. data/run_tests.sh +6 -0
  22. data/spec/api_spec.rb +34 -0
  23. data/spec/builder_spec.rb +262 -0
  24. data/spec/fixtures/AndroidStrings.txt +21 -0
  25. data/spec/fixtures/Strings.txt +47 -0
  26. data/spec/fixtures/project.git/.gitignore +1 -0
  27. data/spec/fixtures/project.git/BUILD.json +7 -0
  28. data/spec/fixtures/project.git/Code/Project.h +0 -0
  29. data/spec/fixtures/project.git/Code/Project.m +0 -0
  30. data/spec/fixtures/project.git/Gemfile +3 -0
  31. data/spec/fixtures/project.git/Gemfile.lock +38 -0
  32. data/spec/fixtures/project.git/HEAD +1 -0
  33. data/spec/fixtures/project.git/LICENSE +1 -0
  34. data/spec/fixtures/project.git/Podfile +6 -0
  35. data/spec/fixtures/project.git/Podfile.lock +14 -0
  36. data/spec/fixtures/project.git/Project.podspec +14 -0
  37. data/spec/fixtures/project.git/TestProject/Images.xcassets/AppIcon.appiconset/Contents.json +23 -0
  38. data/spec/fixtures/project.git/TestProject/Images.xcassets/LaunchImage.launchimage/Contents.json +23 -0
  39. data/spec/fixtures/project.git/TestProject/TATPAppDelegate.h +15 -0
  40. data/spec/fixtures/project.git/TestProject/TATPAppDelegate.m +49 -0
  41. data/spec/fixtures/project.git/TestProject/TestProject-Info.plist +38 -0
  42. data/spec/fixtures/project.git/TestProject/TestProject-Prefix.pch +16 -0
  43. data/spec/fixtures/project.git/TestProject/en.lproj/InfoPlist.strings +1 -0
  44. data/spec/fixtures/project.git/TestProject/main.m +18 -0
  45. data/spec/fixtures/project.git/TestProject.xcodeproj/project.pbxproj +1020 -0
  46. data/spec/fixtures/project.git/TestProject.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  47. data/spec/fixtures/project.git/TestProject.xcodeproj/project.xcworkspace/xcuserdata/blake.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  48. data/spec/fixtures/project.git/TestProject.xcodeproj/xcuserdata/blake.xcuserdatad/xcschemes/TestProject.xcscheme +96 -0
  49. data/spec/fixtures/project.git/TestProject.xcodeproj/xcuserdata/blake.xcuserdatad/xcschemes/xcschememanagement.plist +27 -0
  50. data/spec/fixtures/project.git/TestProject.xcworkspace/contents.xcworkspacedata +1 -0
  51. data/spec/fixtures/project.git/TestProjectTests/TestProjectTests-Info.plist +22 -0
  52. data/spec/fixtures/project.git/TestProjectTests/TestProjectTests.m +34 -0
  53. data/spec/fixtures/project.git/TestProjectTests/en.lproj/InfoPlist.strings +1 -0
  54. data/spec/fixtures/project.git/VERSION +1 -0
  55. data/spec/fixtures/project.git/config +7 -0
  56. data/spec/fixtures/project.git/description +1 -0
  57. data/spec/fixtures/project.git/index +0 -0
  58. data/spec/fixtures/project.git/info/exclude +6 -0
  59. data/spec/fixtures/project.git/logs/HEAD +1 -0
  60. data/spec/fixtures/project.git/logs/refs/heads/master +1 -0
  61. data/spec/fixtures/project.git/objects/00/a6b3f80ebbe4019f03461416061e8805e6eab1 +0 -0
  62. data/spec/fixtures/project.git/objects/03/c303d5552f29d366d11a13448c3c18e94c3bfa +0 -0
  63. data/spec/fixtures/project.git/objects/03/ff7c3a95a196ac8ad1d53db2bd4fb4c80507c1 +0 -0
  64. data/spec/fixtures/project.git/objects/0a/7123364a174ffda52d29a18cdd31fd325bbd6c +0 -0
  65. data/spec/fixtures/project.git/objects/0d/183cba8b0a5e477ea1d001130c222af19b8324 +0 -0
  66. data/spec/fixtures/project.git/objects/0e/6ba5232c3c2f8a7e435794e845b5dc9f339d8b +0 -0
  67. data/spec/fixtures/project.git/objects/25/5b4ee687ed1337cffb10e6d07bb89ee6e5d180 +0 -0
  68. data/spec/fixtures/project.git/objects/25/60a2b9ab9323ca61a0fdebd3b4af46dbe4c272 +0 -0
  69. data/spec/fixtures/project.git/objects/2b/f8bd93d56787a7548c7f8960a94f05c269b486 +0 -0
  70. data/spec/fixtures/project.git/objects/38/439105a884d2556443c7b5c645034e67fb7987 +0 -0
  71. data/spec/fixtures/project.git/objects/3e/efcb9dd5b38e2c1dc061052455dd97bcd51e6c +0 -0
  72. data/spec/fixtures/project.git/objects/53/8b3019ab68814604fbc8e017d09b690c22728c +0 -0
  73. data/spec/fixtures/project.git/objects/59/c178850684e21fafbebedeff15b2b522402af2 +0 -0
  74. data/spec/fixtures/project.git/objects/62/037867910d9aa803d7e02addc26574e270d3d8 +0 -0
  75. data/spec/fixtures/project.git/objects/66/05c1af131470a3b635d166f2591917b32f3b82 +0 -0
  76. data/spec/fixtures/project.git/objects/69/67e396037a52d8300eb9dc8a1e9f7155dd55bf +0 -0
  77. data/spec/fixtures/project.git/objects/6b/5ad4043aee9bc0936466760665f870d4f2f40f +0 -0
  78. data/spec/fixtures/project.git/objects/6c/fc746d4ecf2e3ac67bb0cf6c4013e1aff9b1f1 +0 -0
  79. data/spec/fixtures/project.git/objects/6f/3b0ab36651ca648408c176f81e4b2e202efa0b +0 -0
  80. data/spec/fixtures/project.git/objects/74/3435c9bee5c433fe166891e698fdc70d81a3de +0 -0
  81. data/spec/fixtures/project.git/objects/96/81bfb8ec019f74df384cfb66d68e94bd6d9005 +0 -0
  82. data/spec/fixtures/project.git/objects/99/fa9259e929fe3bee4791ff2a63070fc0358c0a +3 -0
  83. data/spec/fixtures/project.git/objects/a1/5f8980cfbf126a9a0b3ddf7fb1c3fbd6480934 +2 -0
  84. data/spec/fixtures/project.git/objects/a3/96706db4ec4cfca4d984d38b90dc8098bded40 +1 -0
  85. data/spec/fixtures/project.git/objects/b4/42134ccda2b0b1813288e7e04a401a4bef2b59 +0 -0
  86. data/spec/fixtures/project.git/objects/b9/2732c79e00cf2fad5ceceb61bbc7a9a9739d2c +0 -0
  87. data/spec/fixtures/project.git/objects/ba/01f5352549018dfdb95423b9e0974443ec0346 +1 -0
  88. data/spec/fixtures/project.git/objects/ba/8dd7d2162334426facd310f62ed923eb6f4cf5 +0 -0
  89. data/spec/fixtures/project.git/objects/bf/422763a0101a5971e15d53581acb825b4d38b8 +0 -0
  90. data/spec/fixtures/project.git/objects/c7/9ebd3ada1309bae694b8e6760592b1254e035c +2 -0
  91. data/spec/fixtures/project.git/objects/ca/7ced48ee61e517fc57576a33dc9d95f5d4f539 +2 -0
  92. data/spec/fixtures/project.git/objects/ce/eed5f059b6d374d08e0b1e732463842b3a5a91 +0 -0
  93. data/spec/fixtures/project.git/objects/d7/89fd591fee7d26c2f40c6614b5a91931377f88 +0 -0
  94. data/spec/fixtures/project.git/objects/d8/ec4dbb2804f53fd863cd0adb830c5bf4e85a1d +0 -0
  95. data/spec/fixtures/project.git/objects/dc/680e07f12748657d5a798495f08ce3ad884f0b +0 -0
  96. data/spec/fixtures/project.git/objects/de/de871ad5691708aca809557a823082a70dde69 +0 -0
  97. data/spec/fixtures/project.git/objects/e0/30730e56be52e4dc293c829f73e0c586073ad2 +0 -0
  98. data/spec/fixtures/project.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
  99. data/spec/fixtures/project.git/objects/e6/f7f8a92eb3177d10a809b96f41905e9be4cc2b +0 -0
  100. data/spec/fixtures/project.git/objects/ed/7115c4ae4c1885ee75f6ffe946b559546efd28 +0 -0
  101. data/spec/fixtures/project.git/objects/f1/e01dd1256054d5717ef0c89008f0a22639e273 +2 -0
  102. data/spec/fixtures/project.git/objects/f9/3e9c03a56aba331bcd98cb2ef00ba0003de285 +0 -0
  103. data/spec/fixtures/project.git/refs/heads/master +1 -0
  104. data/spec/fixtures/search.json +14159 -0
  105. data/spec/fixtures/search_results_1-50.html +1076 -0
  106. data/spec/fixtures/search_results_101-110.html +476 -0
  107. data/spec/fixtures/search_results_51-100.html +1076 -0
  108. data/spec/fixtures/translation_details.html +728 -0
  109. data/spec/fixtures/translation_details.json +738 -0
  110. data/spec/spec_helper.rb +28 -0
  111. data/spec/strings_file_spec.rb +225 -0
  112. data/spec/translation_spec.rb +21 -0
  113. data/spec/translation_tool_spec.rb +146 -0
  114. data/trip_advisor.gemspec +38 -0
  115. metadata +474 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 37b68982a31da5d78d1dada2e1cbeea00866d469
4
+ data.tar.gz: c4f085998646ab79ab6bee99bbea4a8aba0463b4
5
+ SHA512:
6
+ metadata.gz: 2a1ed3a13ab73984766aaf58df02f2922adddc3b8bc15f1e75db442e9bff0ac3ccc4a4a66e0dd24b8b3acb86826e2ab261391816dc20251d8678da6b76215eab
7
+ data.tar.gz: a574629b28a8d3dc9844c250c1eb8db074f2972604438f1444bf8e3867d2f5e67cf0d52452ee165cf039eb8084b772e4ecf276b19d0c176a5a90fde25cf722fe
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,52 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
+ #
20
+ # * Create a file at ~/.gitignore
21
+ # * Include files you want ignored
22
+ # * Run: git config --global core.excludesfile ~/.gitignore
23
+ #
24
+ # After doing this, these files will be ignored in all your git projects,
25
+ # saving you from having to 'pollute' every project you touch with them
26
+ #
27
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
+ #
29
+ # For MacOS:
30
+ #
31
+ #.DS_Store
32
+
33
+ # For TextMate
34
+ #*.tmproj
35
+ #tmtags
36
+
37
+ # For emacs:
38
+ #*~
39
+ #\#*
40
+ #.\#*
41
+
42
+ # For vim:
43
+ #*.swp
44
+
45
+ # For redcar:
46
+ #.redcar
47
+
48
+ # For rubinius:
49
+ #*.rbc
50
+
51
+ # /bin
52
+ bin
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p598
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ script: bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in trip_advisor.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,118 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ trip_advisor (0.0.15)
5
+ addressable (~> 2.3.5)
6
+ cocoapods (~> 0.34.2)
7
+ highline (~> 1.6.19)
8
+ nokogiri (~> 1.6.0)
9
+ oj (~> 2.1.6)
10
+ rest-client (~> 1.6.7)
11
+ rugged (~> 0.19.0)
12
+ twine (~> 0.4.0)
13
+ xcpretty (~> 0.1.7)
14
+
15
+ GEM
16
+ remote: https://rubygems.org/
17
+ specs:
18
+ activesupport (3.2.21)
19
+ i18n (~> 0.6, >= 0.6.4)
20
+ multi_json (~> 1.0)
21
+ addressable (2.3.6)
22
+ claide (0.7.0)
23
+ cocoapods (0.34.4)
24
+ activesupport (>= 3.2.15, < 4)
25
+ claide (~> 0.7.0)
26
+ cocoapods-core (= 0.34.4)
27
+ cocoapods-downloader (~> 0.7.2)
28
+ cocoapods-plugins (~> 0.3.1)
29
+ cocoapods-trunk (~> 0.3.1)
30
+ cocoapods-try (~> 0.4.1)
31
+ colored (~> 1.2)
32
+ escape (~> 0.0.4)
33
+ json_pure (~> 1.8)
34
+ nap (~> 0.8)
35
+ open4 (~> 1.3)
36
+ xcodeproj (~> 0.19.4)
37
+ cocoapods-core (0.34.4)
38
+ activesupport (>= 3.2.15)
39
+ fuzzy_match (~> 2.0.4)
40
+ json_pure (~> 1.8)
41
+ nap (~> 0.8.0)
42
+ cocoapods-downloader (0.7.2)
43
+ cocoapods-plugins (0.3.2)
44
+ nap
45
+ cocoapods-trunk (0.3.1)
46
+ json_pure (~> 1.8)
47
+ nap (>= 0.8)
48
+ netrc (= 0.7.8)
49
+ cocoapods-try (0.4.3)
50
+ colored (1.2)
51
+ crack (0.4.2)
52
+ safe_yaml (~> 1.0.0)
53
+ diff-lcs (1.2.5)
54
+ escape (0.0.4)
55
+ excon (0.26.0)
56
+ fuzzy_match (2.0.4)
57
+ highline (1.6.21)
58
+ i18n (0.7.0)
59
+ json (1.8.2)
60
+ json_pure (1.8.2)
61
+ mime-types (1.25.1)
62
+ mini_portile (0.6.2)
63
+ multi_json (1.10.1)
64
+ nap (0.8.0)
65
+ netrc (0.7.8)
66
+ nokogiri (1.6.6.2)
67
+ mini_portile (~> 0.6.0)
68
+ oj (2.1.7)
69
+ open4 (1.3.4)
70
+ rake (10.4.2)
71
+ rdoc (4.2.0)
72
+ json (~> 1.4)
73
+ rest-client (1.6.8)
74
+ mime-types (~> 1.16)
75
+ rdoc (>= 2.4.2)
76
+ rspec (2.14.1)
77
+ rspec-core (~> 2.14.0)
78
+ rspec-expectations (~> 2.14.0)
79
+ rspec-mocks (~> 2.14.0)
80
+ rspec-core (2.14.8)
81
+ rspec-expectations (2.14.5)
82
+ diff-lcs (>= 1.1.3, < 2.0)
83
+ rspec-mocks (2.14.6)
84
+ ruby_parser (3.6.3)
85
+ sexp_processor (~> 4.1)
86
+ rubyzip (0.9.9)
87
+ rugged (0.19.0)
88
+ safe_yaml (1.0.4)
89
+ sexp_processor (4.4.4)
90
+ simplecov (0.7.1)
91
+ multi_json (~> 1.0)
92
+ simplecov-html (~> 0.7.1)
93
+ simplecov-html (0.7.1)
94
+ tomdoc (0.2.5)
95
+ colored
96
+ ruby_parser (>= 2.0.4)
97
+ twine (0.4.0)
98
+ rubyzip (~> 0.9.5)
99
+ webmock (1.13.0)
100
+ addressable (>= 2.2.7)
101
+ crack (>= 0.3.2)
102
+ xcodeproj (0.19.4)
103
+ activesupport (~> 3.0)
104
+ colored (~> 1.2)
105
+ xcpretty (0.1.10)
106
+
107
+ PLATFORMS
108
+ ruby
109
+
110
+ DEPENDENCIES
111
+ bundler (~> 1.7)
112
+ excon (~> 0.26.0)
113
+ rake
114
+ rspec (~> 2.14.0)
115
+ simplecov (~> 0.7.1)
116
+ tomdoc (~> 0.2.5)
117
+ trip_advisor!
118
+ webmock (~> 1.13.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Blake Watters
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,23 @@
1
+ Trip Advisor
2
+ ============
3
+
4
+ [![Build Status](https://magnum.travis-ci.com/GateGuru/trip_advisor.png?token=SBJXqCxG7QrbzehxzzMq&branch=master)](https://magnum.travis-ci.com/GateGuru/trip_advisor)
5
+
6
+ This gem provides a simple, well tested interface to a number of TripAdvisor internal API's that are useful when
7
+ developing application.
8
+
9
+ ## Features
10
+
11
+ * Provides access to the TripAdvisor Translation Tool
12
+
13
+ ## Credits
14
+
15
+ Blake Watters
16
+
17
+ - http://github.com/blakewatters
18
+ - http://twitter.com/blakewatters
19
+ - bwatters@tripadvisor.com
20
+
21
+ ## License
22
+
23
+ The TripAdvisor Gem is proprietary software copyright (c) TripAdvisor 2013. All rights reserved.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require "bundler/gem_tasks"
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task :default => :spec
@@ -0,0 +1,45 @@
1
+ module TripAdvisor
2
+ class API
3
+ attr_accessor :base_url, :api_key
4
+ attr_writer :verbose
5
+
6
+ def initialize(options={})
7
+ require 'rest-client'
8
+ require 'addressable/uri'
9
+ require 'oj'
10
+
11
+ self.api_key = options[:api_key]
12
+ self.base_url = options[:base_url] || ENV['TRIPADVISOR_API_BASE_URL'] || 'https://www.tripadvisor.com/api/internal/1.0/'
13
+ raise "API Key cannot be nil" unless api_key
14
+ end
15
+
16
+ def base_url=(base_url)
17
+ @base_url = base_url.is_a?(String) ? Addressable::URI.parse(base_url) : base_url
18
+ end
19
+
20
+ def get_locales
21
+ response = get(:locales)
22
+ Oj.load(response)['data']
23
+ end
24
+
25
+ def get_flights_locales
26
+ get_locales.select { |locale| locale['is_mobile_flights_enabled'] == 'true' }
27
+ end
28
+
29
+ def verbose?
30
+ @verbose
31
+ end
32
+
33
+ def get(method, params = {})
34
+ query_string = "?%s" % Addressable::URI.form_encode(params.merge('key' => api_key))
35
+ url = Addressable::URI.join(base_url, method.to_s, query_string)
36
+ puts_verbose("GET URL '#{url}'")
37
+ RestClient.get(url.to_s)
38
+ end
39
+
40
+ private
41
+ def puts_verbose(string)
42
+ puts(string) if verbose?
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,221 @@
1
+ require 'rugged'
2
+ require 'oj'
3
+ require 'time'
4
+
5
+ module TripAdvisor
6
+ class BuildInfo
7
+ attr_accessor :version, :branch, :sha1, :author
8
+ attr_reader :date
9
+
10
+ def initialize(repo)
11
+ @date = Time.now
12
+ @branch = repo.branches.detect { |b| b.canonical_name == repo.head.name }.name
13
+ name = repo.config['user.name']
14
+ email = repo.config['user.email']
15
+ @author = "#{name} <#{email}>"
16
+ @sha1 = repo.head.target
17
+ end
18
+
19
+ def timestamp
20
+ date.utc.strftime("%Y%m%d%H%M%S")
21
+ end
22
+
23
+ def to_hash
24
+ Hash.new.tap do |info|
25
+ info['version'] = self.version
26
+ info['branch'] = self.branch
27
+ info['sha1'] = self.sha1
28
+ info['author'] = self.author
29
+ info['date'] = self.date.utc.iso8601
30
+ end
31
+ end
32
+ end
33
+
34
+ class NullReporter
35
+ def say(message)
36
+ nil
37
+ end
38
+ end
39
+
40
+ class ConsoleReporter
41
+ def say(message)
42
+ puts message
43
+ end
44
+ end
45
+
46
+ class AbstractBuild
47
+ attr_reader :path, :repo, :info
48
+ attr_accessor :pod_repo, :reporter, :version_prefix, :remotes
49
+
50
+ def initialize(path)
51
+ @path = path
52
+ @repo = Rugged::Repository.new(path)
53
+ @info = BuildInfo.new(repo)
54
+ @pod_repo = "tripadvisor"
55
+ @reporter = ConsoleReporter.new
56
+ @version_prefix = 'v'
57
+ end
58
+
59
+ def build!
60
+ raise "Cannot build a TripAdvisor::AbstractBuild: Only concrete subclasses are buildable."
61
+ end
62
+
63
+ def podspec_file
64
+ @podspec_file ||= Dir.entries(path).detect { |f| f =~ /.podspec$/ }
65
+ end
66
+
67
+ def remotes
68
+ if @remotes.nil?
69
+ @remotes = `git remote`.split("\n")
70
+ raise "Build failed: Non-zero exit status returned while executing `git remote`" unless $?.success?
71
+ end
72
+ @remotes
73
+ end
74
+
75
+ def run(command)
76
+ unless system(command)
77
+ raise "Build failed: Non-zero exit status returned while executing `#{command}`"
78
+ end
79
+ end
80
+
81
+ def pod_update!
82
+ run("bundle exec pod update")
83
+ end
84
+
85
+ def release_version
86
+ File.read(File.join(path, 'VERSION')).chomp
87
+ end
88
+
89
+ def author
90
+ @author ||= { name: repo.config['user.name'], email: repo.config['user.email'], time: Time.now }
91
+ end
92
+
93
+ def update_build_assets
94
+ info.version = version
95
+ File.open('BUILD.json', 'w') { |f| f << Oj.dump(info.to_hash) }
96
+ podspec_content = File.read(podspec_file)
97
+ unless podspec_content.gsub!(/(\.version\s+=\s+)['"](.+)['"]$/, "\\1'#{version}'")
98
+ raise "Unable to update version of Podspec: version attribute not matched."
99
+ end
100
+ unless podspec_content.gsub!(/(\:tag\s+=>\s+)['"](.+)['"]/, "\\1'#{tag_name}'")
101
+ raise "Unable to update version of Podspec: version attribute not matched."
102
+ end
103
+ File.open(podspec_file, 'w') { |f| f << podspec_content }
104
+ end
105
+
106
+ def commit!(files)
107
+ say "Committing to #{path}"
108
+ index = repo.index
109
+ files.each { |f| index.add f }
110
+
111
+ options = {}
112
+ options[:tree] = index.write_tree(repo)
113
+
114
+ options[:author] = author
115
+ options[:committer] = author
116
+ options[:message] = "Creating build #{version}"
117
+ options[:parents] = [ repo.head.target ]
118
+ options[:update_ref] = 'HEAD'
119
+
120
+ Rugged::Commit.create(repo, options)
121
+ end
122
+
123
+ def tag!(target)
124
+ Rugged::Tag.create(repo,
125
+ :name => tag_name,
126
+ :message => "Tagging build #{version}",
127
+ :target => target,
128
+ :tagger => author)
129
+ end
130
+
131
+ def push!
132
+ branch = info.branch
133
+ remotes.each do |remote_name|
134
+ say "Pushing to remote '#{remote_name}'"
135
+ # NOTE: Rugged apparently cannot push to the repositories we need
136
+ # remote = Rugged::Remote.lookup(@repo, remote_name)
137
+ # remote.push ["refs/heads/#{info.branch}", "refs/tags/#{tag_name}"]
138
+ run("git push #{remote_name} #{branch}:#{branch} --tags")
139
+ end
140
+ end
141
+
142
+ def push_podspec!
143
+ run("bundle exec pod repo push #{pod_repo} #{podspec_file}")
144
+ end
145
+
146
+ def update_staging_area(files)
147
+ run("git add #{files.join(' ')}")
148
+ end
149
+
150
+ protected
151
+ def say(message)
152
+ reporter.say(message)
153
+ end
154
+ end
155
+
156
+ class AdHocBuild < AbstractBuild
157
+ def build!
158
+ say "Creating AdHoc build at path: #{path}"
159
+ Dir.chdir(path) do
160
+ update_build_assets
161
+ pod_update!
162
+ files = [podspec_file, 'BUILD.json', 'Podfile.lock']
163
+ target = commit!(files)
164
+ say "Committed updates to #{files.join(', ')} (ref: #{target})"
165
+ tag!(target)
166
+ say "Tagged build as #{tag_name}"
167
+ push!
168
+ say "Pushed to #{remotes.join(', ')}"
169
+ push_podspec!
170
+ say "Pushed podspec to spec repository '#{pod_repo}'"
171
+ update_staging_area(files)
172
+ end
173
+ say "Build complete."
174
+ end
175
+
176
+ def version
177
+ @version ||= "#{release_version}-b#{info.timestamp}"
178
+ end
179
+
180
+ def tag_name
181
+ "builds/#{version_prefix}#{version}"
182
+ end
183
+ end
184
+
185
+ class ReleaseBuild < AbstractBuild
186
+ attr_accessor :release_version
187
+
188
+ def initialize(path, release_version)
189
+ super(path)
190
+ @release_version = release_version
191
+ File.write(File.join(path, 'VERSION'), "#{release_version}")
192
+ end
193
+
194
+ def build!
195
+ say "Creating Release build at path: #{path}"
196
+ Dir.chdir(path) do
197
+ update_build_assets
198
+ pod_update!
199
+ files = [podspec_file, 'BUILD.json', 'Podfile.lock', 'VERSION']
200
+ target = commit!(files)
201
+ say "Committed updates to #{files.join(', ')} (ref: #{target})"
202
+ tag!(target)
203
+ say "Tagged build as #{tag_name}"
204
+ push!
205
+ say "Pushed to #{remotes.join(', ')}"
206
+ push_podspec!
207
+ say "Pushed podspec to spec repository '#{pod_repo}'"
208
+ update_staging_area(files)
209
+ end
210
+ say "Build complete."
211
+ end
212
+
213
+ def version
214
+ @version ||= "#{release_version}"
215
+ end
216
+
217
+ def tag_name
218
+ "#{version_prefix}#{version}"
219
+ end
220
+ end
221
+ end