aweplug 1.0.0.a16 → 1.0.0.a17

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,95 +1,98 @@
1
1
  require 'yaml/store'
2
2
  require 'fileutils'
3
3
 
4
- module Aweplug::Cache
5
- # Public: A simple caching implementation.
6
- # Internally it using a YAML::Store for a file backing. It also saves
7
- # data in a hash for the life of the object. Any keys which are
8
- # Strings are frozen before being used.
9
- class YamlFileCache
10
- # Public: Initialization method.
11
- #
12
- # opts - A Hash of options
13
- # filename: Name of the File used for caching. Defaults to
14
- # 'tmp/cache.store'.
15
- #
16
- # Examples
17
- #
18
- # store = Aweplug::Cache::YamlFileCache.new
19
- # store.write('key', 'data')
20
- # # => 'data'
21
- # store.read('key')
22
- # # => 'data'
23
- #
24
- # Returns a new instance of the cache.
25
- def initialize(opts = {})
26
- opts.merge!({filename: '_tmp/cache.store'})
27
- FileUtils.mkdir_p(File.dirname opts[:filename])
28
- @file_store = YAML::Store.new opts[:filename]
29
- @memory_store = {}
30
- end
4
+ module Aweplug
5
+ module Cache
6
+ # Public: A simple caching implementation.
7
+ # Internally it using a YAML::Store for a file backing. It also saves
8
+ # data in a hash for the life of the object. Any keys which are
9
+ # Strings are frozen before being used.
10
+ class YamlFileCache
11
+ # Public: Initialization method.
12
+ #
13
+ # opts - A Hash of options
14
+ # filename: Name of the File used for caching. Defaults to
15
+ # 'tmp/cache.store'.
16
+ #
17
+ # Examples
18
+ #
19
+ # store = Aweplug::Cache::YamlFileCache.new
20
+ # store.write('key', 'data')
21
+ # # => 'data'
22
+ # store.read('key')
23
+ # # => 'data'
24
+ #
25
+ # Returns a new instance of the cache.
26
+ def initialize(opts = {})
27
+ opts.merge!({filename: '_tmp/cache.store'})
28
+ FileUtils.mkdir_p(File.dirname opts[:filename])
29
+ @file_store = YAML::Store.new opts[:filename]
30
+ @memory_store = {}
31
+ end
31
32
 
32
- # Public: Retrieves the data stored previously under the given key.
33
- #
34
- # key - key part of a key value pair
35
- #
36
- # Examples
37
- #
38
- # store.read('my_key')
39
- # # => 'my_data'
40
- #
41
- # Returns the data associated with the key.
42
- def read(key)
43
- key.freeze if key.is_a? String
33
+ # Public: Retrieves the data stored previously under the given key.
34
+ #
35
+ # key - key part of a key value pair
36
+ #
37
+ # Examples
38
+ #
39
+ # store.read('my_key')
40
+ # # => 'my_data'
41
+ #
42
+ # Returns the data associated with the key.
43
+ def read(key)
44
+ key.freeze if key.is_a? String
44
45
 
45
- if @memory_store.has_key? key
46
- @memory_store[key]
47
- else
48
- @file_store.transaction do
49
- @memory_store[key] = @file_store[key]
46
+ if @memory_store.has_key? key
47
+ @memory_store[key]
48
+ else
49
+ @file_store.transaction do
50
+ @memory_store[key] = @file_store[key]
51
+ end
52
+ @memory_store[key]
50
53
  end
51
- @memory_store[key]
52
54
  end
53
- end
54
55
 
55
- # Public: Adds data to the cache.
56
- #
57
- # key - A key for the cache, strings or symbols should be used
58
- # value - Data to store in the cache
59
- #
60
- # Examples
61
- #
62
- # store.write(:pi, 3.14)
63
- # # => 3.14
64
- #
65
- # Returns the data just saved.
66
- def write(key, value)
67
- key.freeze if key.is_a? String
56
+ # Public: Adds data to the cache.
57
+ #
58
+ # key - A key for the cache, strings or symbols should be used
59
+ # value - Data to store in the cache
60
+ #
61
+ # Examples
62
+ #
63
+ # store.write(:pi, 3.14)
64
+ # # => 3.14
65
+ #
66
+ # Returns the data just saved.
67
+ def write(key, value)
68
+ key.freeze if key.is_a? String
68
69
 
69
- @memory_store[key] = value
70
- @file_store.transaction do
71
- @file_store[key] = value
70
+ @memory_store[key] = value
71
+ @file_store.transaction do
72
+ @file_store[key] = value
73
+ end
72
74
  end
73
- end
74
75
 
75
- # Public: Retreives the value from the cache, or the return of the Block.
76
- #
77
- # key - Key in the cache to retreive.
78
- # block - The block to be evaluated for a default value.
79
- #
80
- # Examples
81
- #
82
- # store.fetch(key) { 'new data' }
83
- # # => 'new data'
84
- # store.write(key, 23)
85
- # store.fetch(key) { 'new data' }
86
- # # => 23
87
- #
88
- # Returns the value in the cache, or the default supplied from the block.
89
- def fetch(key)
90
- key.freeze if key.is_a? String
76
+ # Public: Retreives the value from the cache, or the return of the Block.
77
+ #
78
+ # key - Key in the cache to retreive.
79
+ # block - The block to be evaluated for a default value.
80
+ #
81
+ # Examples
82
+ #
83
+ # store.fetch(key) { 'new data' }
84
+ # # => 'new data'
85
+ # store.write(key, 23)
86
+ # store.fetch(key) { 'new data' }
87
+ # # => 23
88
+ #
89
+ # Returns the value in the cache, or the default supplied from the block.
90
+ def fetch(key)
91
+ key.freeze if key.is_a? String
91
92
 
92
- read(key) || yield.tap { |data| write(key, data) }
93
+ read(key) || yield.tap { |data| write(key, data) }
94
+ end
93
95
  end
94
96
  end
95
97
  end
98
+
@@ -5,125 +5,126 @@ require 'aweplug/helpers/searchisko'
5
5
  require 'json'
6
6
  require 'pry'
7
7
 
8
- module Aweplug::Extensions
9
- # Public: An awestruct extension for guides / examples written in AsciiDoc.
10
- # Files with the .asciidoc or .adoc extension are considered to be
11
- # AsciiDoc files. This extension makes use of asciidoctor to
12
- # render the files.
13
- #
14
- # Example
15
- #
16
- # extension Aweplug::Extensions::AsciidocExample({...})
17
- class AsciidocExample
18
- include Aweplug::Helper::Git::Commit::Metadata
19
- include Aweplug::Helper::Git::Repository
20
-
21
- # Public: Initialization method, used in the awestruct pipeline.
8
+ module Aweplug
9
+ module Extensions
10
+ # Public: An awestruct extension for guides / examples written in AsciiDoc.
11
+ # Files with the .asciidoc or .adoc extension are considered to be
12
+ # AsciiDoc files. This extension makes use of asciidoctor to
13
+ # render the files.
14
+ #
15
+ # Example
22
16
  #
23
- # opts - A Hash of options, some being required, some not (default: {}).
24
- # :repository - The String name of the directory
25
- # containing the repository (required).
26
- # :directory - The String directory name, within the
27
- # :respository, containing the files
28
- # (required).
29
- # :layout - The String name of the layout to use,
30
- # omitting the extension (required).
31
- # :output_dir - The String or Pathname of the output
32
- # directory for the files (required).
33
- # :additional_excludes - An Array of Strings containing
34
- # additional base file names to exclude
35
- # (default: []).
36
- # :recurse_subdirectories - Boolean flag indicating to continue
37
- # searching subdirectories (default:
38
- # true).
39
- # :additional_metadata_keys - An Array of String keys from the
40
- # AsciiDoc metadata to include in the
41
- # searchisko payload (default: []).
42
- # :site_variable - String name of the key within the site
43
- # containing additional metadata about
44
- # the guide (default: value of
45
- # :output_dir).
46
- # Returns the created extension.
47
- def initialize(opts = {})
48
- required_keys = [:repository, :directory, :layout, :output_dir, :site_variable]
49
- opts = {additional_excludes: [], recurse_subdirectories: true,
50
- additional_metadata_keys: [], site_variable: opts[:output_dir]}.merge opts
51
- missing_required_keys = required_keys - opts.keys
17
+ # extension Aweplug::Extensions::AsciidocExample({...})
18
+ class AsciidocExample
19
+ include Aweplug::Helper::Git::Commit::Metadata
20
+ include Aweplug::Helper::Git::Repository
52
21
 
53
- raise ArgumentError.new "Missing required arguments #{missing_required_keys.join ', '}" unless missing_required_keys.empty?
22
+ # Public: Initialization method, used in the awestruct pipeline.
23
+ #
24
+ # opts - A Hash of options, some being required, some not (default: {}).
25
+ # :repository - The String name of the directory
26
+ # containing the repository (required).
27
+ # :directory - The String directory name, within the
28
+ # :respository, containing the files
29
+ # (required).
30
+ # :layout - The String name of the layout to use,
31
+ # omitting the extension (required).
32
+ # :output_dir - The String or Pathname of the output
33
+ # directory for the files (required).
34
+ # :additional_excludes - An Array of Strings containing
35
+ # additional base file names to exclude
36
+ # (default: []).
37
+ # :recurse_subdirectories - Boolean flag indicating to continue
38
+ # searching subdirectories (default:
39
+ # true).
40
+ # :additional_metadata_keys - An Array of String keys from the
41
+ # AsciiDoc metadata to include in the
42
+ # searchisko payload (default: []).
43
+ # :site_variable - String name of the key within the site
44
+ # containing additional metadata about
45
+ # the guide (default: value of
46
+ # :output_dir).
47
+ # Returns the created extension.
48
+ def initialize(opts = {})
49
+ required_keys = [:repository, :directory, :layout, :output_dir, :site_variable]
50
+ opts = {additional_excludes: [], recurse_subdirectories: true,
51
+ additional_metadata_keys: [], site_variable: opts[:output_dir]}.merge opts
52
+ missing_required_keys = required_keys - opts.keys
54
53
 
55
- @repo = opts[:repository]
56
- @output_dir = Pathname.new opts[:output_dir]
57
- @layout = opts[:layout]
58
- @recurse_subdirectories = opts[:recurse_subdirectories]
59
- @additional_metadata_keys = opts[:additional_metadata_keys]
60
- @additional_excludes = opts[:additional_excludes]
61
- @directory = File.join opts[:repository], opts[:directory]
62
- @site_variable = opts[:site_variable]
63
- end
54
+ raise ArgumentError.new "Missing required arguments #{missing_required_keys.join ', '}" unless missing_required_keys.empty?
64
55
 
65
- # Internal: Execute method required by awestruct. Called during the
66
- # pipeline execution. No return.
67
- #
68
- # site - The site instance from awestruct.
69
- #
70
- # Returns nothing.
71
- def execute site
72
- searchisko = Aweplug::Helpers::Searchisko.new({:base_url => site.dcp_base_url,
73
- :authenticate => true,
74
- :searchisko_username => ENV['dcp_user'],
75
- :searchisko_password => ENV['dcp_password'],
76
- :logger => site.profile == 'developement'})
77
- Find.find @directory do |path|
78
- Find.prune if File.directory?(path) && !@recurse_subdirectories
56
+ @repo = opts[:repository]
57
+ @output_dir = Pathname.new opts[:output_dir]
58
+ @layout = opts[:layout]
59
+ @recurse_subdirectories = opts[:recurse_subdirectories]
60
+ @additional_metadata_keys = opts[:additional_metadata_keys]
61
+ @additional_excludes = opts[:additional_excludes]
62
+ @directory = File.join opts[:repository], opts[:directory]
63
+ @site_variable = opts[:site_variable]
64
+ end
79
65
 
80
- next if File.directory?(path) # If it's a directory, start recursing
66
+ # Internal: Execute method required by awestruct. Called during the
67
+ # pipeline execution. No return.
68
+ #
69
+ # site - The site instance from awestruct.
70
+ #
71
+ # Returns nothing.
72
+ def execute site
73
+ searchisko = Aweplug::Helpers::Searchisko.new({:base_url => site.dcp_base_url,
74
+ :authenticate => true,
75
+ :searchisko_username => ENV['dcp_user'],
76
+ :searchisko_password => ENV['dcp_password'],
77
+ :logger => site.profile == 'developement'})
78
+ Find.find @directory do |path|
79
+ Find.prune if File.directory?(path) && !@recurse_subdirectories
81
80
 
82
- Find.prune if File.extname(path) !~ /\.a(scii)?doc/ || @additional_excludes.include?(File.basename path)
81
+ next if File.directory?(path) # If it's a directory, start recursing
83
82
 
84
- page = site.engine.load_site_page path
85
- page.layout = @layout
86
- page.output_path = File.join(@output_dir, File.basename(page.output_path))
83
+ Find.prune if File.extname(path) !~ /\.a(scii)?doc/ || @additional_excludes.include?(File.basename path)
87
84
 
88
- doc = Asciidoctor.load_file path
89
- metadata = {:author => doc.author, :commits => commit_info(@repo, path),
90
- :title => doc.doctitle, :tags => doc.attributes['tags'],
91
- :toc => doc.sections.inject([]) {|result, elm| result << {:id => elm.id, :text => elm.title}; result},
92
- :github_repo_url => repository_url(@repo),
93
- # Will need to strip html tags for summary
94
- :summary => doc.sections.first.render}
85
+ page = site.engine.load_site_page path
86
+ page.layout = @layout
87
+ page.output_path = File.join(@output_dir, File.basename(page.output_path))
95
88
 
96
- page.send('metadata=', metadata)
97
- site.pages << page
89
+ doc = Asciidoctor.load_file path
90
+ metadata = {:author => doc.author, :commits => commit_info(@repo, path),
91
+ :title => doc.doctitle, :tags => doc.attributes['tags'],
92
+ :toc => doc.sections.inject([]) {|result, elm| result << {:id => elm.id, :text => elm.title}; result},
93
+ :github_repo_url => repository_url(@repo),
94
+ # Will need to strip html tags for summary
95
+ :summary => doc.sections.first.render}
98
96
 
99
- searchisko_hash = {
100
- :sys_title => metadata[:title],
101
- :sys_content_id => Digest::SHA1.hexdigest(metadata[:title])[0..7], # maybe change?
102
- :sys_description => metadata[:summary],
103
- :sys_content => doc.render,
104
- :sys_url_view => "#{site.base_url}#{site.ctx_root.nil? ? '/' : '/' + site.ctx_root + '/'}#{page.output_path}",
105
- :"sys_content_content-type" => 'text/html',
106
- :sys_type => 'jbossdeveloper_example',
107
- :sys_content_type => 'example',
108
- :sys_content_provider => 'jboss-developer',
109
- :contributors => metadata[:commits].collect { |c| c[:author] }.unshift(metadata[:author]).uniq,
110
- :sys_created => metadata[:commits].collect { |c| DateTime.parse c[:date] }.last,
111
- :sys_activity_dates => metadata[:commits].collect { |c| DateTime.parse c[:date] },
112
- :sys_updated => metadata[:commits].collect { |c| DateTime.parse c[:date] }.first
113
- }
97
+ page.send('metadata=', metadata)
98
+ site.pages << page
114
99
 
115
- @additional_metadata_keys.inject(searchisko_hash) do |hash, key|
116
- hash[key.to_sym] = doc.attributes[key]
117
- hash
118
- end
100
+ searchisko_hash = {
101
+ :sys_title => metadata[:title],
102
+ :sys_content_id => Digest::SHA1.hexdigest(metadata[:title])[0..7], # maybe change?
103
+ :sys_description => metadata[:summary],
104
+ :sys_content => doc.render,
105
+ :sys_url_view => "#{site.base_url}#{site.ctx_root.nil? ? '/' : '/' + site.ctx_root + '/'}#{page.output_path}",
106
+ :"sys_content_content-type" => 'text/html',
107
+ :sys_type => 'jbossdeveloper_example',
108
+ :sys_content_type => 'example',
109
+ :sys_content_provider => 'jboss-developer',
110
+ :contributors => metadata[:commits].collect { |c| c[:author] }.unshift(metadata[:author]).uniq,
111
+ :sys_created => metadata[:commits].collect { |c| DateTime.parse c[:date] }.last,
112
+ :sys_activity_dates => metadata[:commits].collect { |c| DateTime.parse c[:date] },
113
+ :sys_updated => metadata[:commits].collect { |c| DateTime.parse c[:date] }.first
114
+ }
119
115
 
120
- unless site.profile =~ /development/
121
- searchisko.push_content(searchisko_hash[:sys_type],
122
- searchisko_hash[:sys_content_id],
123
- searchisko_hash.to_json)
116
+ @additional_metadata_keys.inject(searchisko_hash) do |hash, key|
117
+ hash[key.to_sym] = doc.attributes[key]
118
+ hash
119
+ end
120
+
121
+ unless site.profile =~ /development/
122
+ searchisko.push_content(searchisko_hash[:sys_type],
123
+ searchisko_hash[:sys_content_id],
124
+ searchisko_hash.to_json)
125
+ end
124
126
  end
125
127
  end
126
128
  end
127
129
  end
128
130
  end
129
-
@@ -33,6 +33,8 @@ module Aweplug
33
33
  # containing additional metadata about
34
34
  # the guide (default: value of
35
35
  # :output_dir).
36
+ # :excludes - Array of Strings containing additional
37
+ # directory names to exclude. Defaults to [].
36
38
  # Returns the created extension.
37
39
  def initialize opts = {}
38
40
  required_keys = [:repository, :layout, :output_dir]
@@ -43,6 +45,7 @@ module Aweplug
43
45
  @output_dir = Pathname.new opts[:output_dir]
44
46
  @layout = opts[:layout]
45
47
  @site_variable = opts[:site_variable] || opts[:output_dir]
48
+ @excludes = opts[:excludes] || []
46
49
  end
47
50
 
48
51
  # Internal: Execute method required by awestruct. Called during the
@@ -60,6 +63,8 @@ module Aweplug
60
63
  :searchisko_password => ENV['dcp_password'],
61
64
  :logger => site.profile == 'developement'})
62
65
  Dir["#{@repo}/**/README.md"].each do |file|
66
+ next if @excludes.include?(File.dirname(file))
67
+
63
68
  page = add_to_site site, file
64
69
 
65
70
  metadata = extract_metadata(file)
@@ -0,0 +1,76 @@
1
+ require 'aweplug/helpers/vimeo'
2
+ require 'json'
3
+
4
+ module Aweplug
5
+ module Extensions
6
+ module Video
7
+ # Public: Awestruct Extension which iterates over a site variable which
8
+ # contains vimeo URLs and creates pages out of them, also sends the info
9
+ # over to a searchisko instance for indexing.
10
+ class Vimeo
11
+ include Aweplug::Helpers::Vimeo
12
+
13
+ # Public: Creates a new instance of this Awestruct plugin.
14
+ #
15
+ # variable_name - Name of the variable in the Awestruct Site containing
16
+ # the list of vimeo videos.
17
+ # layout - Name of the layout to be used for the generated Pages.
18
+ #
19
+ # Returns a new instance of this extension.
20
+ def initialize variable_name, layout
21
+ @variable = variable_name
22
+ @layout = layout
23
+ end
24
+
25
+ def execute site
26
+ @site = site
27
+ searchisko = Aweplug::Helpers::Searchisko.new({:base_url => site.dcp_base_url,
28
+ :authenticate => true,
29
+ :searchisko_username => ENV['dcp_user'],
30
+ :searchisko_password => ENV['dcp_password'],
31
+ :logger => site.profile == 'developement'})
32
+
33
+ site[@variable].each do |url|
34
+ id = url.match(/^.*\/(\d*)$/)[1]
35
+ page_path = Pathname.new(File.join 'video', 'vimeo', "#{id}.html")
36
+ page = ::Awestruct::Page.new(site,
37
+ ::Awestruct::Handlers::LayoutHandler.new(site,
38
+ ::Awestruct::Handlers::TiltHandler.new(site,
39
+ ::Aweplug::Handlers::SyntheticHandler.new(site, '', page_path))))
40
+ page.layout = @layout
41
+ page.output_path = File.join 'video', 'vimeo', id,'index.html'
42
+ video = Aweplug::Helpers::Vimeo::Video.new url, access_token, site
43
+ page.send('video=', video)
44
+ page.send('video_url=', url)
45
+ site.pages << page
46
+
47
+ unless video.fetch_info['title'].include? 'Unable to fetch'
48
+ searchisko_payload = {
49
+ :sys_type => 'jbossdeveloper_video',
50
+ :sys_content_provider => 'jboss-developer',
51
+ :sys_content_type => 'video',
52
+ :sys_content_id => video.id,
53
+ :sys_updated => video.modified_date,
54
+ :sys_contributors => video.cast,
55
+ :sys_activity_dates => [video.modified_date, video.upload_date],
56
+ :sys_created => video.upload_date,
57
+ :sys_title => video.title,
58
+ :sys_url_view => "http://vimeo.com/#{video.id}",
59
+ :sys_description => video.description,
60
+ :duration => video.duration,
61
+ :thumbnail => video.thumb_url,
62
+ :tag => video.tags
63
+ }
64
+
65
+ unless site.profile =~ /development/
66
+ searchisko.push_content(searchisko_payload[:sys_type],
67
+ searchisko_payload[:sys_content_id],
68
+ searchisko_payload.to_json)
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -2,103 +2,106 @@ require 'faraday'
2
2
  require 'faraday_middleware'
3
3
  require 'aweplug/cache/yaml_file_cache'
4
4
 
5
- module Aweplug::Helpers
6
- # Public: A helper class for using Searchisko.
7
- class Searchisko
8
- # Public: Initialization of the object, keeps a Faraday connection cached.
9
- #
10
- # opts - symbol keyed hash. Current keys used:
11
- # :base_url - base url for the searchisko instance
12
- # :authenticate - boolean flag for authentication
13
- # :searchisko_username - Username to use for auth
14
- # :searchisko_password - Password to use for auth
15
- # :logging - Boolean to log responses
16
- # :raise_error - Boolean flag if 404 and 500 should raise exceptions
17
- # :adapter - faraday adapter to use, defaults to :net_http
18
- #
19
- # Returns a new instance of Searchisko.
20
- def initialize opts={}
21
- @faraday = Faraday.new(:url => opts[:base_url]) do |builder|
22
- if opts[:authenticate]
23
- if opts[:searchisko_username] && opts[:searchisko_password]
24
- builder.request :basic_auth, opts[:searchisko_username], opts[:searchisko_password]
25
- else
26
- $LOG.warn 'Missing username and / or password for searchisko'
5
+ module Aweplug
6
+ module Helpers
7
+ # Public: A helper class for using Searchisko.
8
+ class Searchisko
9
+ # Public: Initialization of the object, keeps a Faraday connection cached.
10
+ #
11
+ # opts - symbol keyed hash. Current keys used:
12
+ # :base_url - base url for the searchisko instance
13
+ # :authenticate - boolean flag for authentication
14
+ # :searchisko_username - Username to use for auth
15
+ # :searchisko_password - Password to use for auth
16
+ # :logging - Boolean to log responses
17
+ # :raise_error - Boolean flag if 404 and 500 should raise exceptions
18
+ # :adapter - faraday adapter to use, defaults to :net_http
19
+ #
20
+ # Returns a new instance of Searchisko.
21
+ def initialize opts={}
22
+ @faraday = Faraday.new(:url => opts[:base_url]) do |builder|
23
+ if opts[:authenticate]
24
+ if opts[:searchisko_username] && opts[:searchisko_password]
25
+ builder.request :basic_auth, opts[:searchisko_username], opts[:searchisko_password]
26
+ else
27
+ $LOG.warn 'Missing username and / or password for searchisko'
28
+ end
27
29
  end
30
+ builder.response :logger if opts[:logging]
31
+ builder.response :raise_error if opts[:raise_error]
32
+ builder.use FaradayMiddleware::Caching, Aweplug::Cache::YamlFileCache.new, {}
33
+ #builder.response :json, :content_type => /\bjson$/
34
+ builder.adapter opts[:adapter] || :net_http
28
35
  end
29
- builder.response :logger if opts[:logging]
30
- builder.response :raise_error if opts[:raise_error]
31
- builder.use FaradayMiddleware::Caching, Aweplug::Cache::YamlFileCache.new, {}
32
- #builder.response :json, :content_type => /\bjson$/
33
- builder.adapter opts[:adapter] || :net_http
34
36
  end
35
- end
36
37
 
37
- # Public: Performs a GET search against the Searchisko instance using
38
- # provided parameters.
39
- #
40
- # params - Hash of parameters to use as query string. See
41
- # http://docs.jbossorg.apiary.io/#searchapi for more information
42
- # about parameters and how they affect the search.
43
- #
44
- # Example
45
- #
46
- # searchisko.search {:query => 'Search query'}
47
- # # => {...}
48
- #
49
- # Returns the String result of the search.
50
- def search params = {}
51
- get '/search', params
52
- end
38
+ # Public: Performs a GET search against the Searchisko instance using
39
+ # provided parameters.
40
+ #
41
+ # params - Hash of parameters to use as query string. See
42
+ # http://docs.jbossorg.apiary.io/#searchapi for more information
43
+ # about parameters and how they affect the search.
44
+ #
45
+ # Example
46
+ #
47
+ # searchisko.search {:query => 'Search query'}
48
+ # # => {...}
49
+ #
50
+ # Returns the String result of the search.
51
+ def search params = {}
52
+ get '/search', params
53
+ end
53
54
 
54
- # Public: Makes an HTTP GET to host/v1/rest/#{path} and returns the
55
- # result from the Faraday request.
56
- #
57
- # path - String containing the rest of the path.
58
- # params - Hash containing query string parameters.
59
- #
60
- # Example
61
- #
62
- # searchisko.get 'feed', {:query => 'Search Query'}
63
- # # => Faraday Response Object
64
- #
65
- # Returns the Faraday Response for the request.
66
- def get path, params = {}
67
- @faraday.get "/v1/rest/" + path, params
68
- end
55
+ # Public: Makes an HTTP GET to host/v1/rest/#{path} and returns the
56
+ # result from the Faraday request.
57
+ #
58
+ # path - String containing the rest of the path.
59
+ # params - Hash containing query string parameters.
60
+ #
61
+ # Example
62
+ #
63
+ # searchisko.get 'feed', {:query => 'Search Query'}
64
+ # # => Faraday Response Object
65
+ #
66
+ # Returns the Faraday Response for the request.
67
+ def get path, params = {}
68
+ @faraday.get "/v1/rest/" + path, params
69
+ end
69
70
 
70
- # Public: Posts content to Searchisko.
71
- #
72
- # content_type - String of the Searchisko sys_content_type for the content
73
- # being posted.
74
- # content_id - String of the Searchisko sys_content_id for the content.
75
- # params - Hash containing the content to push.
76
- #
77
- # Examples
78
- #
79
- # searchisko.push_content 'jbossdeveloper_bom', id, content_hash
80
- # # => Faraday Response
81
- #
82
- # Returns a Faraday Response from the POST.
83
- def push_content content_type, content_id, params = {}
84
- post "/content/#{content_type}/#{content_id}", params
85
- end
71
+ # Public: Posts content to Searchisko.
72
+ #
73
+ # content_type - String of the Searchisko sys_content_type for the content
74
+ # being posted.
75
+ # content_id - String of the Searchisko sys_content_id for the content.
76
+ # params - Hash containing the content to push.
77
+ #
78
+ # Examples
79
+ #
80
+ # searchisko.push_content 'jbossdeveloper_bom', id, content_hash
81
+ # # => Faraday Response
82
+ #
83
+ # Returns a Faraday Response from the POST.
84
+ def push_content content_type, content_id, params = {}
85
+ post "/content/#{content_type}/#{content_id}", params
86
+ end
86
87
 
87
- # Public: Perform an HTTP POST to Searchisko.
88
- #
89
- # path - String containing the rest of the path.
90
- # params - Hash containing the POST body.
91
- #
92
- # Examples
93
- #
94
- # searchisko.post "rating/#{searchisko_document_id}", {rating: 3}
95
- # # => Faraday Response
96
- def post path, params = {}
97
- @faraday.post do |req|
98
- req.url "/v1/rest/" + path
99
- req.headers['Content-Type'] = 'application/json'
100
- req.body = params
88
+ # Public: Perform an HTTP POST to Searchisko.
89
+ #
90
+ # path - String containing the rest of the path.
91
+ # params - Hash containing the POST body.
92
+ #
93
+ # Examples
94
+ #
95
+ # searchisko.post "rating/#{searchisko_document_id}", {rating: 3}
96
+ # # => Faraday Response
97
+ def post path, params = {}
98
+ @faraday.post do |req|
99
+ req.url "/v1/rest/" + path
100
+ req.headers['Content-Type'] = 'application/json'
101
+ req.body = params
102
+ end
101
103
  end
102
104
  end
103
105
  end
104
106
  end
107
+
@@ -59,11 +59,12 @@ module Aweplug
59
59
  #
60
60
  # full_name - the full name, e.g. Pete Muir
61
61
  def first_name(full_name)
62
- full_name.split[0]
62
+ full_name.split[0] || full_name
63
63
  end
64
64
 
65
65
  # Internal: Data object to hold and parse values from the Vimeo API.
66
66
  class Video
67
+ include Aweplug::Helpers::Vimeo
67
68
  def initialize(url, access_token, site)
68
69
  @id = url.match(/^.*\/(\d*)$/)[1]
69
70
  @site = site
@@ -106,23 +107,42 @@ module Aweplug
106
107
  end
107
108
  end
108
109
  end
109
- out
110
+ out || ''
110
111
  end
111
112
 
112
113
  def author
113
114
  if @cast[0]
114
115
  @cast[0]
115
116
  else
116
- @cast = Openstruct.new({"realname" => "Unknown"})
117
+ @cast = OpenStruct.new({"realname" => "Unknown"})
117
118
  end
118
119
  end
119
120
 
120
121
  def cast
121
- @cast
122
+ @cast || ''
123
+ end
124
+
125
+ def modified_date
126
+ if @video["upload_date"]
127
+ DateTime.parse(@video["upload_date"]).strftime("%F %T")
128
+ else
129
+ "UNKOWN DATE"
130
+ end
131
+ end
132
+
133
+ def tags
134
+ if @video['tags'].is_a? Hash
135
+ @video['tags']['tag'].inject([]) do |result, element|
136
+ result << element['normalized']
137
+ result
138
+ end
139
+ else
140
+ ''
141
+ end
122
142
  end
123
143
 
124
144
  def thumb_url
125
- @thumb["_content"]
145
+ @thumb["_content"] || ''
126
146
  end
127
147
 
128
148
  def fetch_info
@@ -135,22 +155,27 @@ module Aweplug
135
155
  end
136
156
 
137
157
  def fetch_thumb_url
138
- body = exec_method "vimeo.videos.getThumbnailUrls", @id
139
- if body
140
- @thumb = JSON.parse(body)["thumbnails"]["thumbnail"][1]
158
+ if @video['thumbnails']
159
+ @thumb = @video["thumbnails"]["thumbnail"][1]
141
160
  else
142
161
  @thumb = {"_content" => ""}
143
162
  end
144
163
  end
145
164
 
146
165
  def fetch_cast
147
- body = exec_method "vimeo.videos.getCast", @id
148
166
  @cast = []
149
- if body
150
- JSON.parse(body)["cast"]["member"].each do |c|
151
- o = OpenStruct.new(c)
152
- if o.username != "jbossdeveloper"
153
- @cast << o
167
+ if @video['cast']
168
+ cast = @video["cast"]
169
+ if cast['total'] != '1'
170
+ cast["member"].each do |c|
171
+ o = OpenStruct.new(c)
172
+ if o.username != "jbossdeveloper"
173
+ @cast << o
174
+ end
175
+ end
176
+ else
177
+ if cast['member']['username'] != 'jbossdeveloper'
178
+ @cast << OpenStruct.new(cast['member'])
154
179
  end
155
180
  end
156
181
  end
@@ -163,44 +188,28 @@ module Aweplug
163
188
  #
164
189
  # Returns JSON retreived from the Vimeo API
165
190
  def exec_method(method, video_id)
191
+ # TODO: Look at switching this to faraday
166
192
  if access_token
167
193
  query = "http://vimeo.com/api/rest/v2?method=#{method}&video_id=#{video_id}&format=json"
168
194
  access_token.get(query).body
169
195
  end
170
196
  end
197
+ end
171
198
 
172
- # Internal: Obtains an OAuth::AcccessToken for the Vimeo API, using the
173
- # vimeo_client_id and vimeo_access_token defined in site/config.yml and
174
- # vimeo_client_secret and vimeo_access_token_secret defined in environment
175
- # variables
176
- #
177
- # site - Awestruct Site instance
178
- #
179
- # Returns an OAuth::AccessToken for the Vimeo API
180
- def access_token
181
- if @access_token
182
- @access_token
183
- else
184
- if not ENV['vimeo_client_secret']
185
- puts 'Cannot fetch video info from vimeo, vimeo_client_secret is missing from environment variables'
186
- return
187
- end
188
- if not @site.vimeo_client_id
189
- puts 'Cannot fetch video info vimeo, vimeo_client_id is missing from _config/site.yml'
190
- return
191
- end
192
- if not ENV['vimeo_access_token_secret']
193
- puts 'Cannot fetch video info from vimeo, vimeo_access_token_secret is missing from environment variables'
194
- return
195
- end
196
- if not @site.vimeo_access_token
197
- puts 'Cannot fetch video info from vimeo, vimeo_access_token is missing from _config/site.yml'
198
- return
199
- end
200
- consumer = OAuth::Consumer.new(@site.vimeo_client_id, ENV['vimeo_client_secret'],
201
- { :site => "https://vimeo.com",
202
- :scheme => :header
203
- })
199
+ # Internal: Obtains an OAuth::AcccessToken for the Vimeo API, using the
200
+ # vimeo_client_id and vimeo_access_token defined in site/config.yml and
201
+ # vimeo_client_secret and vimeo_access_token_secret defined in environment
202
+ # variables
203
+ #
204
+ # site - Awestruct Site instance
205
+ #
206
+ # Returns an OAuth::AccessToken for the Vimeo API
207
+ def access_token
208
+ if @access_token
209
+ @access_token
210
+ else
211
+ if not ENV['vimeo_client_secret']
212
+ puts 'Cannot fetch video info from vimeo, vimeo_client_secret is missing from environment variables'
204
213
  # now create the access token object from passed values
205
214
  token_hash = { :oauth_token => @site.vimeo_access_token,
206
215
  :oauth_token_secret => ENV['vimeo_access_token_secret']
@@ -1,4 +1,4 @@
1
1
  module Aweplug
2
- VERSION='1.0.0.a16'
2
+ VERSION='1.0.0.a17'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aweplug
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.a16
4
+ version: 1.0.0.a17
5
5
  prerelease: 6
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: 2014-02-15 00:00:00.000000000 Z
12
+ date: 2014-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: octokit
@@ -166,6 +166,7 @@ files:
166
166
  - lib/aweplug/extensions/asciidoc_example.rb
167
167
  - lib/aweplug/extensions/kramdown_quickstart.rb
168
168
  - lib/aweplug/extensions/sections.rb
169
+ - lib/aweplug/extensions/vimeo.rb
169
170
  - lib/aweplug/handlers/synthetic_handler.rb
170
171
  - lib/aweplug/helpers/.gitkeep
171
172
  - lib/aweplug/helpers/git_metadata.rb
@@ -190,7 +191,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
191
  version: '0'
191
192
  segments:
192
193
  - 0
193
- hash: -3016901967987087946
194
+ hash: -3243289337858499691
194
195
  required_rubygems_version: !ruby/object:Gem::Requirement
195
196
  none: false
196
197
  requirements: