euston-websites 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Gemfile.lock +39 -0
- data/Rakefile +161 -0
- data/euston-websites.gemspec +36 -0
- data/lib/euston-websites.rb +8 -0
- data/lib/euston-websites/api_command_request_parsing/abstract_parser.rb +34 -0
- data/lib/euston-websites/api_command_request_parsing/batch_parser.rb +16 -0
- data/lib/euston-websites/api_command_request_parsing/discrete_parser.rb +23 -0
- data/lib/euston-websites/api_version.rb +36 -0
- data/lib/euston-websites/version.rb +5 -0
- metadata +123 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
euston-websites (1.0.0)
|
5
|
+
activesupport (>= 3.0.10)
|
6
|
+
hollywood
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (3.1.1)
|
12
|
+
multi_json (~> 1.0)
|
13
|
+
awesome_print (0.4.0)
|
14
|
+
diff-lcs (1.1.3)
|
15
|
+
fuubar (0.0.6)
|
16
|
+
rspec (~> 2.0)
|
17
|
+
rspec-instafail (~> 0.1.8)
|
18
|
+
ruby-progressbar (~> 0.0.10)
|
19
|
+
hollywood (1.0.0)
|
20
|
+
multi_json (1.0.3)
|
21
|
+
rspec (2.6.0)
|
22
|
+
rspec-core (~> 2.6.0)
|
23
|
+
rspec-expectations (~> 2.6.0)
|
24
|
+
rspec-mocks (~> 2.6.0)
|
25
|
+
rspec-core (2.6.4)
|
26
|
+
rspec-expectations (2.6.0)
|
27
|
+
diff-lcs (~> 1.1.2)
|
28
|
+
rspec-instafail (0.1.9)
|
29
|
+
rspec-mocks (2.6.0)
|
30
|
+
ruby-progressbar (0.0.10)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
awesome_print (~> 0.4.0)
|
37
|
+
euston-websites!
|
38
|
+
fuubar (~> 0.0.0)
|
39
|
+
rspec (~> 2.6.0)
|
data/Rakefile
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
#############################################################################
|
5
|
+
#
|
6
|
+
# Helper functions
|
7
|
+
#
|
8
|
+
#############################################################################
|
9
|
+
|
10
|
+
def name
|
11
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
12
|
+
end
|
13
|
+
|
14
|
+
def version
|
15
|
+
line = File.read("lib/#{name}/version.rb")[/^\s*VERSION\s*=\s*.*/]
|
16
|
+
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
17
|
+
end
|
18
|
+
|
19
|
+
def date
|
20
|
+
Date.today.to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
def rubyforge_project
|
24
|
+
name
|
25
|
+
end
|
26
|
+
|
27
|
+
def gemspec_file
|
28
|
+
"#{name}.gemspec"
|
29
|
+
end
|
30
|
+
|
31
|
+
def gem_file
|
32
|
+
"#{name}-#{version}.gem"
|
33
|
+
end
|
34
|
+
|
35
|
+
def replace_header(head, header_name, provider = nil)
|
36
|
+
if provider
|
37
|
+
value = send(provider)
|
38
|
+
else
|
39
|
+
value = "'#{send(header_name)}'"
|
40
|
+
end
|
41
|
+
|
42
|
+
provider ||= header_name
|
43
|
+
head.sub!(/(\.#{header_name}\s*= ).*/) { "#{$1}#{value}"}
|
44
|
+
end
|
45
|
+
|
46
|
+
def platform
|
47
|
+
jruby? ? '-java' : ''
|
48
|
+
end
|
49
|
+
|
50
|
+
def platform_dependant_gem_file
|
51
|
+
"#{name}-#{version}#{platform}.gem"
|
52
|
+
end
|
53
|
+
|
54
|
+
def platform_dependent_version
|
55
|
+
"'#{version}#{platform}'"
|
56
|
+
end
|
57
|
+
|
58
|
+
def jruby?
|
59
|
+
RUBY_PLATFORM.to_s == 'java'
|
60
|
+
end
|
61
|
+
|
62
|
+
def trim_array_ends array
|
63
|
+
array.shift
|
64
|
+
array.pop
|
65
|
+
array
|
66
|
+
end
|
67
|
+
|
68
|
+
#############################################################################
|
69
|
+
#
|
70
|
+
# Custom tasks
|
71
|
+
#
|
72
|
+
#############################################################################
|
73
|
+
|
74
|
+
default_rspec_opts = %w[--colour --format Fuubar]
|
75
|
+
|
76
|
+
desc "Run all examples"
|
77
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
78
|
+
t.rspec_opts = default_rspec_opts
|
79
|
+
end
|
80
|
+
|
81
|
+
#############################################################################
|
82
|
+
#
|
83
|
+
# Packaging tasks
|
84
|
+
#
|
85
|
+
#############################################################################
|
86
|
+
|
87
|
+
def built_gem
|
88
|
+
@built_gem ||= Dir["#{name}*.gem"].first
|
89
|
+
end
|
90
|
+
|
91
|
+
desc "Create tag v#{platform_dependent_version} and build and push #{platform_dependant_gem_file} to Rubygems"
|
92
|
+
task :release => :build do
|
93
|
+
unless `git branch` =~ /^\* master$/
|
94
|
+
puts "You must be on the master branch to release!"
|
95
|
+
exit!
|
96
|
+
end
|
97
|
+
|
98
|
+
sh "git commit --allow-empty -a -m 'Release #{platform_dependent_version}'"
|
99
|
+
sh "git tag v#{platform_dependent_version}"
|
100
|
+
sh "git push origin master"
|
101
|
+
sh "git push origin v#{platform_dependent_version}"
|
102
|
+
|
103
|
+
command = "gem push pkg/#{platform_dependant_gem_file}"
|
104
|
+
|
105
|
+
if jruby?
|
106
|
+
puts "--------------------------------------------------------------------------------------"
|
107
|
+
puts "can't push to rubygems using jruby at the moment, so switch to mri and run: #{command}"
|
108
|
+
puts "--------------------------------------------------------------------------------------"
|
109
|
+
else
|
110
|
+
sh command
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
desc "Build #{platform_dependant_gem_file} into the pkg directory"
|
115
|
+
task :build => :gemspec do
|
116
|
+
sh "mkdir -p pkg"
|
117
|
+
sh "gem build #{gemspec_file}"
|
118
|
+
sh "mv #{built_gem} pkg"
|
119
|
+
end
|
120
|
+
|
121
|
+
desc "Generate #{gemspec_file}"
|
122
|
+
task :gemspec => :validate do
|
123
|
+
# read spec file and split out manifest section
|
124
|
+
spec = File.read(gemspec_file)
|
125
|
+
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
126
|
+
|
127
|
+
# replace name version and date
|
128
|
+
replace_header(head, :name)
|
129
|
+
replace_header(head, :version)
|
130
|
+
replace_header(head, :date)
|
131
|
+
#comment this out if your rubyforge_project has a different name
|
132
|
+
#replace_header(head, :rubyforge_project)
|
133
|
+
|
134
|
+
# determine file list from git ls-files
|
135
|
+
files = `git ls-files`.
|
136
|
+
split("\n").
|
137
|
+
sort.
|
138
|
+
reject { |file| file =~ /^\./ }.
|
139
|
+
reject { |file| file =~ /^(rdoc|pkg)/ }.
|
140
|
+
map { |file| " #{file}" }.
|
141
|
+
join("\n")
|
142
|
+
|
143
|
+
# piece file back together and write
|
144
|
+
manifest = " s.files = %w[\n#{files}\n ]\n"
|
145
|
+
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
146
|
+
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
147
|
+
puts "Updated #{gemspec_file}"
|
148
|
+
end
|
149
|
+
|
150
|
+
desc "Validate #{gemspec_file}"
|
151
|
+
task :validate do
|
152
|
+
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
|
153
|
+
unless libfiles.empty?
|
154
|
+
puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
|
155
|
+
exit!
|
156
|
+
end
|
157
|
+
unless Dir['VERSION*'].empty?
|
158
|
+
puts "A `VERSION` file at root level violates Gem best practices."
|
159
|
+
exit!
|
160
|
+
end
|
161
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'euston-websites'
|
3
|
+
s.version = '1.0.0'
|
4
|
+
s.platform = RUBY_PLATFORM.to_s == 'java' ? 'java' : Gem::Platform::RUBY
|
5
|
+
s.authors = ['Lee Henson', 'Guy Boertje']
|
6
|
+
s.email = ['lee.m.henson@gmail.com', 'guyboertje@gmail.com']
|
7
|
+
s.summary = %q{Common functionality for interacting with euston from websites.}
|
8
|
+
s.description = ""
|
9
|
+
s.homepage = 'http://github.com/leemhenson/euston-websites'
|
10
|
+
|
11
|
+
# = MANIFEST =
|
12
|
+
s.files = %w[
|
13
|
+
Gemfile
|
14
|
+
Gemfile.lock
|
15
|
+
Rakefile
|
16
|
+
euston-websites.gemspec
|
17
|
+
lib/euston-websites.rb
|
18
|
+
lib/euston-websites/api_command_request_parsing/abstract_parser.rb
|
19
|
+
lib/euston-websites/api_command_request_parsing/batch_parser.rb
|
20
|
+
lib/euston-websites/api_command_request_parsing/discrete_parser.rb
|
21
|
+
lib/euston-websites/api_version.rb
|
22
|
+
lib/euston-websites/version.rb
|
23
|
+
]
|
24
|
+
# = MANIFEST =
|
25
|
+
|
26
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
27
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
28
|
+
|
29
|
+
s.add_dependency 'activesupport', '>= 3.0.10'
|
30
|
+
s.add_dependency 'hash-keys', '~> 1.0.1'
|
31
|
+
s.add_dependency 'hollywood', '~> 1.0.0'
|
32
|
+
|
33
|
+
s.add_development_dependency 'awesome_print', '~> 0.4.0'
|
34
|
+
s.add_development_dependency 'fuubar', '~> 0.0.0'
|
35
|
+
s.add_development_dependency 'rspec', '~> 2.6.0'
|
36
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'active_support/json'
|
2
|
+
require 'hash-keys'
|
3
|
+
require 'hollywood'
|
4
|
+
|
5
|
+
require 'euston-websites/api_version'
|
6
|
+
require 'euston-websites/api_command_request_parsing/abstract_parser'
|
7
|
+
require 'euston-websites/api_command_request_parsing/batch_parser'
|
8
|
+
require 'euston-websites/api_command_request_parsing/discrete_parser'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Euston
|
2
|
+
module Websites
|
3
|
+
module ApiCommandRequestParsing
|
4
|
+
class AbstractParser
|
5
|
+
include Hollywood
|
6
|
+
|
7
|
+
def initialize request
|
8
|
+
@body = request.body.read
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse
|
12
|
+
valid = true
|
13
|
+
|
14
|
+
begin
|
15
|
+
commands = [transform_hash_to_commands(ActiveSupport::JSON.decode(@body))].flatten
|
16
|
+
rescue StandardError => e
|
17
|
+
callback :not_parseable
|
18
|
+
valid = false
|
19
|
+
end
|
20
|
+
|
21
|
+
return unless valid
|
22
|
+
|
23
|
+
invalid_commands = commands.reject { |c| c.valid? }
|
24
|
+
|
25
|
+
if invalid_commands.any?
|
26
|
+
callback :invalid, invalid_commands
|
27
|
+
else
|
28
|
+
callback :valid, commands
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Euston
|
2
|
+
module Websites
|
3
|
+
module ApiCommandRequestParsing
|
4
|
+
class BatchParser < AbstractParser
|
5
|
+
def initialize request, &block
|
6
|
+
super request
|
7
|
+
@transformer = block
|
8
|
+
end
|
9
|
+
|
10
|
+
def transform_hash_to_commands hash
|
11
|
+
@transformer.call hash
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Euston
|
2
|
+
module Websites
|
3
|
+
module ApiCommandRequestParsing
|
4
|
+
class DiscreteParser < AbstractParser
|
5
|
+
def initialize request, params, command_type, command_id = nil
|
6
|
+
super request
|
7
|
+
@command_id = command_id || params[:id]
|
8
|
+
@command_type = command_type
|
9
|
+
end
|
10
|
+
|
11
|
+
def transform_hash_to_commands hash
|
12
|
+
hash = hash.recursive__symbolize__keys!
|
13
|
+
|
14
|
+
callback :preparing_hash, hash
|
15
|
+
|
16
|
+
command = @command_type.new hash
|
17
|
+
command.id = @command_id
|
18
|
+
command
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# Taken from:
|
2
|
+
# http://freelancing-gods.com/posts/versioning_your_ap_is
|
3
|
+
|
4
|
+
module Euston
|
5
|
+
module Websites
|
6
|
+
class ApiVersion
|
7
|
+
def initialize version
|
8
|
+
@version = version
|
9
|
+
end
|
10
|
+
|
11
|
+
def matches? request
|
12
|
+
versioned_accept_header?(request) || version_one?(request)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def vendor_application_id
|
18
|
+
# abstract
|
19
|
+
end
|
20
|
+
|
21
|
+
def version_one? request
|
22
|
+
@version == 1 && unversioned_accept_header?(request)
|
23
|
+
end
|
24
|
+
|
25
|
+
def versioned_accept_header? request
|
26
|
+
accept = request.headers['Accept']
|
27
|
+
accept && accept[/application\/vnd\.#{vendor_application_id}-v#{@version}\+json/]
|
28
|
+
end
|
29
|
+
|
30
|
+
def unversioned_accept_header? request
|
31
|
+
accept = request.headers['Accept']
|
32
|
+
accept.blank? || accept[/application\/vnd\.#{vendor_application_id}/].nil?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: euston-websites
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lee Henson
|
9
|
+
- Guy Boertje
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2011-11-29 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
requirement: &70308955942160 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.10
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *70308955942160
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: hash-keys
|
28
|
+
requirement: &70308955941680 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70308955941680
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: hollywood
|
39
|
+
requirement: &70308955941220 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.0.0
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70308955941220
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: awesome_print
|
50
|
+
requirement: &70308955940760 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.4.0
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *70308955940760
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: fuubar
|
61
|
+
requirement: &70308955331480 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 0.0.0
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *70308955331480
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: &70308955330540 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.6.0
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *70308955330540
|
81
|
+
description: ''
|
82
|
+
email:
|
83
|
+
- lee.m.henson@gmail.com
|
84
|
+
- guyboertje@gmail.com
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- Gemfile
|
90
|
+
- Gemfile.lock
|
91
|
+
- Rakefile
|
92
|
+
- euston-websites.gemspec
|
93
|
+
- lib/euston-websites.rb
|
94
|
+
- lib/euston-websites/api_command_request_parsing/abstract_parser.rb
|
95
|
+
- lib/euston-websites/api_command_request_parsing/batch_parser.rb
|
96
|
+
- lib/euston-websites/api_command_request_parsing/discrete_parser.rb
|
97
|
+
- lib/euston-websites/api_version.rb
|
98
|
+
- lib/euston-websites/version.rb
|
99
|
+
homepage: http://github.com/leemhenson/euston-websites
|
100
|
+
licenses: []
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 1.8.10
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: Common functionality for interacting with euston from websites.
|
123
|
+
test_files: []
|