platform_lib 0.1.1
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/bin/tp_lib +17 -0
- data/lib/platform_lib/data_service.rb +70 -0
- data/lib/platform_lib/media_service.rb +65 -0
- data/lib/platform_lib/service_base.rb +76 -0
- data/lib/platform_lib/task_service.rb +50 -0
- data/lib/platform_lib/version.rb +4 -0
- data/lib/platform_lib/web_helper.rb +44 -0
- data/lib/platform_lib.rb +7 -0
- data/lib/scripts/sync_guid_with_id.rb +62 -0
- data/platform_lib_ruby.gemspec +30 -0
- data/spec/lib/platform_lib/data_service_spec.rb +19 -0
- data/spec/lib/platform_lib/media_service_spec.rb +57 -0
- data/spec/lib/scripts/sync_guid_with_id_spec.rb +1 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/service_support.rb +0 -0
- metadata +171 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 79c97235cb07402a1ddf6fb58dd8839586f6b897
|
4
|
+
data.tar.gz: 414d5aabcdfb1615a2560e2264e54f2a6dc2fec5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eefb7e131eb6903f11d0a17f75d1954ab71743d4bad3c313c1ca8a0acd3b5667ccb0a4b2c183fee05b3eea059cf373958b6c4cd0307363dd4b734a3d72898fa0
|
7
|
+
data.tar.gz: 8efdab29e61471867575365bd3de95276a513efa399c54c0965dd41013b48bd74d10091583eabfe70826f3f5029e10182d89b38bffcd4dd5f96d70935fcf2938
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 David Muto
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Platform Lib Ruby
|
2
|
+
|
3
|
+
[](https://travis-ci.org/ShawONEX/platform_lib_ruby)
|
4
|
+
|
5
|
+
A simple gem to help us work with ThePlatform's Data Service API.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
You'll need to clone the repo and cd into the directory. Then run these:
|
10
|
+
|
11
|
+
$ bundle install
|
12
|
+
$ rake install
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile (if writing code):
|
15
|
+
|
16
|
+
gem 'platform_lib_ruby'
|
17
|
+
|
18
|
+
## Updating
|
19
|
+
|
20
|
+
Navigate to the working directory, and run the following:
|
21
|
+
|
22
|
+
$ gem uninstall platform_lib
|
23
|
+
$ git pull
|
24
|
+
$ bundle install
|
25
|
+
$ rake install
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
The gem will add `tp_lib` to your PATH. This command executes scripts found in
|
30
|
+
the scripts directory.
|
31
|
+
|
32
|
+
Currently there is only one script. Here's how we use it:
|
33
|
+
|
34
|
+
$ tp_lib sync_guid_with_id <user> <pass>
|
35
|
+
|
36
|
+
*Replace `<user>` and `<pass>` with your MPX username and password*
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/tp_lib
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# resolve bin path, ignoring symlinks
|
5
|
+
require "pathname"
|
6
|
+
bin_file = Pathname.new(__FILE__).realpath
|
7
|
+
|
8
|
+
# add self to libpath
|
9
|
+
$:.unshift File.expand_path("../../lib", bin_file)
|
10
|
+
|
11
|
+
require "platform_lib"
|
12
|
+
|
13
|
+
if ARGV.size > 1
|
14
|
+
__send__(ARGV[0], *ARGV[1..-1])
|
15
|
+
else
|
16
|
+
__send__(ARGV[0])
|
17
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "json"
|
2
|
+
require "hashie"
|
3
|
+
require "platform_lib/web_helper"
|
4
|
+
|
5
|
+
module PlatformLib
|
6
|
+
class DataService
|
7
|
+
|
8
|
+
def initialize(username, password)
|
9
|
+
@username = username
|
10
|
+
@password = password
|
11
|
+
@auth_token = nil
|
12
|
+
|
13
|
+
@services = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing(method_name, *args)
|
17
|
+
if method_name =~ /^(.*)_service$/
|
18
|
+
service_by_name($1)
|
19
|
+
else
|
20
|
+
super
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def sign_out
|
25
|
+
return if @auth_token.nil?
|
26
|
+
|
27
|
+
url = AUTH_URL_FORMAT.sub(/ACTION/, 'signOut')
|
28
|
+
url << "&_token=#{@auth_token}"
|
29
|
+
uri = URI.parse(url)
|
30
|
+
|
31
|
+
response = WebHelper::get(uri, :user => @username, :pass => @password)
|
32
|
+
@auth_token = nil
|
33
|
+
@services.clear
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
AUTH_URL_FORMAT = "https://identity.auth.theplatform.com"
|
39
|
+
AUTH_URL_FORMAT << "/idm/web/Authentication/ACTION?schema=1.0&form=json"
|
40
|
+
|
41
|
+
def service_by_name(name)
|
42
|
+
|
43
|
+
# we've already got an instance
|
44
|
+
service = @services[name]
|
45
|
+
|
46
|
+
if service.nil?
|
47
|
+
# create a new service
|
48
|
+
sign_in
|
49
|
+
|
50
|
+
class_name = "#{name.capitalize}Service"
|
51
|
+
service = PlatformLib.const_get(class_name).new(@auth_token)
|
52
|
+
@services[name] = service
|
53
|
+
end
|
54
|
+
|
55
|
+
if block_given?
|
56
|
+
yield(service)
|
57
|
+
else
|
58
|
+
service
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def sign_in
|
63
|
+
uri = URI.parse(AUTH_URL_FORMAT.sub(/ACTION/, 'signIn'))
|
64
|
+
response = WebHelper::get(uri, user: @username, pass: @password)
|
65
|
+
|
66
|
+
response_object = Hashie::Mash.new(JSON.parse(response))
|
67
|
+
@auth_token = response_object.signInResponse.token
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'json'
|
3
|
+
require 'platform_lib/service_base'
|
4
|
+
|
5
|
+
module PlatformLib
|
6
|
+
# Public: A wrapper around the Media Data Service
|
7
|
+
#
|
8
|
+
# Examples:
|
9
|
+
#
|
10
|
+
# # the preferred method
|
11
|
+
# service = PlatformLib::DataService.new("user", "pass").media_service
|
12
|
+
#
|
13
|
+
# # direct instantiation
|
14
|
+
# service = PlatformLib::MediaService.new("auth_token")
|
15
|
+
#
|
16
|
+
class MediaService
|
17
|
+
include ServiceBase
|
18
|
+
|
19
|
+
END_POINT = "http://data.media.theplatform.com/media/data/Media"
|
20
|
+
|
21
|
+
# Public: Creates a new instance
|
22
|
+
#
|
23
|
+
# auth_token - the authentication token to be used
|
24
|
+
def initialize(auth_token)
|
25
|
+
@auth_token = auth_token
|
26
|
+
end
|
27
|
+
|
28
|
+
# Public: Queries the media end point
|
29
|
+
#
|
30
|
+
# params - an optional hash of parameters (query string)
|
31
|
+
# block - an optional block to be called for each item returned
|
32
|
+
#
|
33
|
+
# Examples:
|
34
|
+
#
|
35
|
+
# items = media_service.get_media_items(range: "1-10")
|
36
|
+
#
|
37
|
+
# media_service.get_media_items(byCustomValue: "{test}{val}") do |item|
|
38
|
+
# puts item.title
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# Returns the items supplied from the service
|
42
|
+
def get_media_items(params = {}, &block)
|
43
|
+
if block.nil?
|
44
|
+
get_entries(END_POINT, params)
|
45
|
+
else
|
46
|
+
get_entries(END_POINT, params, &block)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Public: Updates the supplied items and their properties using the
|
51
|
+
# PUT method
|
52
|
+
#
|
53
|
+
# items - an array of items to be updated
|
54
|
+
# params - an optional hash of parameters (query string)
|
55
|
+
#
|
56
|
+
# Example:
|
57
|
+
#
|
58
|
+
# items = [ { id: "id_value", guid: "guid_value" }, .. ]
|
59
|
+
# media_service.update_media_items(items)
|
60
|
+
#
|
61
|
+
def update_media_items(items, params)
|
62
|
+
put_entries("#{END_POINT}/list", params, items)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'hashie'
|
3
|
+
require "platform_lib/web_helper"
|
4
|
+
|
5
|
+
module PlatformLib
|
6
|
+
# Public: Useful methods for working with thePlatform's
|
7
|
+
# This module was intended to be mixed in
|
8
|
+
#
|
9
|
+
# Examples:
|
10
|
+
#
|
11
|
+
# class MyClass
|
12
|
+
# include PlatformLib::ServiceBase
|
13
|
+
# ...
|
14
|
+
# ...
|
15
|
+
# end
|
16
|
+
module ServiceBase
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
# Protected: Performs a get request and returns the "entries" array
|
21
|
+
#
|
22
|
+
# end_point - the https? end point to connect to
|
23
|
+
# params - an optional hash of parameter values (query string)
|
24
|
+
# block - an optional block to be called for each returned entry
|
25
|
+
#
|
26
|
+
# Examples:
|
27
|
+
#
|
28
|
+
# arr = get_entries("http://www.somedomain.com/service", { uid: 10 })
|
29
|
+
#
|
30
|
+
# get_entries("http://www.domain.com") do |single_item|
|
31
|
+
# # do something with the item
|
32
|
+
# end
|
33
|
+
def get_entries(end_point, params = {}, &block)
|
34
|
+
ensure_auth_param(params)
|
35
|
+
|
36
|
+
uri = URI.parse("#{end_point}?#{URI.encode_www_form(params)}")
|
37
|
+
raw = WebHelper::get(uri, token: @auth_token)
|
38
|
+
|
39
|
+
items = JSON.parse(raw)["entries"].map { |item| Hashie::Mash.new(item) }
|
40
|
+
|
41
|
+
if block.nil?
|
42
|
+
items
|
43
|
+
else
|
44
|
+
items.each { |item| block.call(item) }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Protected: Performs a put request, updating the entries
|
49
|
+
#
|
50
|
+
# end_point - the https? end point to connect to
|
51
|
+
# params - an optional hash of parameter values (query string)
|
52
|
+
# entries - the array of entries to be added to the request body
|
53
|
+
#
|
54
|
+
# Examples:
|
55
|
+
#
|
56
|
+
# arr = get_entries("http://www.somedomain.com/service", { uid: 10 })
|
57
|
+
# put_entries(MY_END_POINT, nil, arr)
|
58
|
+
def put_entries(end_point, params = {}, entries)
|
59
|
+
ensure_auth_param(params)
|
60
|
+
|
61
|
+
uri = URI.parse("#{end_point}?#{URI.encode_www_form(params)}")
|
62
|
+
puts uri.to_s
|
63
|
+
body = "{ \"entries\": #{JSON.generate(entries)} }"
|
64
|
+
|
65
|
+
WebHelper::put(uri, body)
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def ensure_auth_param(params)
|
71
|
+
# ensure the token parameter is there
|
72
|
+
params[:token] = @auth_token if not params.has_key?(:token)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'json'
|
3
|
+
require 'platform_lib/service_base'
|
4
|
+
|
5
|
+
module PlatformLib
|
6
|
+
# Public: A wrapper around the Task Data Service
|
7
|
+
#
|
8
|
+
# Examples:
|
9
|
+
#
|
10
|
+
# # the preferred method
|
11
|
+
# service = PlatformLib::DataService.new("user", "pass").task_service
|
12
|
+
#
|
13
|
+
# # direct instantiation
|
14
|
+
# service = PlatformLib::TaskService.new("auth_token")
|
15
|
+
#
|
16
|
+
class TaskService
|
17
|
+
include ServiceBase
|
18
|
+
|
19
|
+
END_POINT = "http://data.task.theplatform.com/task/data/Task"
|
20
|
+
|
21
|
+
# Public: Creates a new instance
|
22
|
+
#
|
23
|
+
# auth_token - the authentication token to be used
|
24
|
+
def initialize(auth_token)
|
25
|
+
@auth_token = auth_token
|
26
|
+
end
|
27
|
+
|
28
|
+
# Public: Queries the task end point
|
29
|
+
#
|
30
|
+
# params - an optional hash of parameters (query string)
|
31
|
+
# block - an optional block to be called for each item returned
|
32
|
+
#
|
33
|
+
# Examples:
|
34
|
+
#
|
35
|
+
# items = task_service.get_task_items(range: "1-10")
|
36
|
+
#
|
37
|
+
# task_service.get_task_items(byCustomValue: "{test}{val}") do |item|
|
38
|
+
# puts item.title
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# Returns the items supplied from the service
|
42
|
+
def get_task_items(params = {}, &block)
|
43
|
+
if block.nil?
|
44
|
+
get_entries(END_POINT, params)
|
45
|
+
else
|
46
|
+
get_entries(END_POINT, params, &block)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "net/https"
|
2
|
+
|
3
|
+
module PlatformLib
|
4
|
+
module WebHelper
|
5
|
+
|
6
|
+
def self.get(uri, auth)
|
7
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
8
|
+
if uri.scheme == "https"
|
9
|
+
http.use_ssl = true
|
10
|
+
end
|
11
|
+
|
12
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
13
|
+
set_auth(request, auth)
|
14
|
+
|
15
|
+
response = http.request(request)
|
16
|
+
if block_given?
|
17
|
+
yield(response.body)
|
18
|
+
else
|
19
|
+
response.body
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.put(uri, body)
|
24
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
25
|
+
if uri.scheme == "https"
|
26
|
+
http.use_ssl = true
|
27
|
+
end
|
28
|
+
|
29
|
+
request = Net::HTTP::Put.new(uri.request_uri)
|
30
|
+
request.content_type = "application/json"
|
31
|
+
request.body = body
|
32
|
+
|
33
|
+
http.request(request)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def self.set_auth(request, auth)
|
39
|
+
if auth.keys.include?(:user) and auth.keys.include?(:pass)
|
40
|
+
request.basic_auth(auth[:user], auth[:pass])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/platform_lib.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#
|
2
|
+
# This script is for our global tv account. Since the migration from feeds2
|
3
|
+
# to feeds3 we began using the guid field to reference the old id's in
|
4
|
+
# MDialog.
|
5
|
+
#
|
6
|
+
# Now that the migration is done, we need new items to copy their id value to
|
7
|
+
# the guid field so the app continues to work correctly.
|
8
|
+
#
|
9
|
+
# This is a temporary measure and will be removed at a later dat
|
10
|
+
#
|
11
|
+
#
|
12
|
+
# To run use tp_lib, like this:
|
13
|
+
#
|
14
|
+
# $ tp_lib sync_with_guid username password
|
15
|
+
#
|
16
|
+
require 'json'
|
17
|
+
|
18
|
+
def sync_guid_with_id(user, pass)
|
19
|
+
|
20
|
+
service = PlatformLib::DataService.new(user, pass)
|
21
|
+
|
22
|
+
params = {
|
23
|
+
fields: "id,guid",
|
24
|
+
schema: "1.6.0",
|
25
|
+
form: "cjson",
|
26
|
+
byCustomValue: "{mDialogIngestSuccess}{true}",
|
27
|
+
range: "1-100",
|
28
|
+
sort: "added|desc",
|
29
|
+
account: "Shaw - GlobalTV"
|
30
|
+
}
|
31
|
+
|
32
|
+
update_params = {
|
33
|
+
schema: "1.2",
|
34
|
+
account: "Shaw - GlobalTV"
|
35
|
+
}
|
36
|
+
|
37
|
+
items = []
|
38
|
+
|
39
|
+
begin
|
40
|
+
service.media_service.get_media_items(params) do |item|
|
41
|
+
# these are the old items
|
42
|
+
next if item.guid =~ /\A\d+\z/
|
43
|
+
|
44
|
+
if item.guid != item.id.split('/').last
|
45
|
+
item.guid = item.id.split('/').last.to_s
|
46
|
+
items << item
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# update the items
|
51
|
+
items.each { |item| item.guid = item.id.split('/').last }
|
52
|
+
|
53
|
+
if items.empty?
|
54
|
+
puts "All items are up to date."
|
55
|
+
else
|
56
|
+
service.media_service.update_media_items(items, update_params)
|
57
|
+
puts "Updated #{items.size} items."
|
58
|
+
end
|
59
|
+
ensure
|
60
|
+
service.sign_out
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'platform_lib/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "platform_lib"
|
8
|
+
spec.version = PlatformLib::VERSION
|
9
|
+
spec.authors = ["David Muto"]
|
10
|
+
spec.email = ["david.muto@shawmedia.ca"]
|
11
|
+
spec.description = %q{Simple library for working with ThePlatform Data Services}
|
12
|
+
spec.summary = %q{Work with ThePlatform Data Services}
|
13
|
+
spec.homepage = "https://github.com/ShawONEX/platform_lib_ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "json"
|
23
|
+
spec.add_dependency "hashie"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "guard-rspec"
|
28
|
+
spec.add_development_dependency "rake"
|
29
|
+
spec.add_development_dependency "tomdoc"
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Data Service" do
|
4
|
+
subject { PlatformLib::DataService.new("user", "password") }
|
5
|
+
|
6
|
+
before do
|
7
|
+
subject.stub(:sign_in)
|
8
|
+
subject.stub(:sign_out)
|
9
|
+
end
|
10
|
+
|
11
|
+
after { subject.sign_out }
|
12
|
+
|
13
|
+
describe "#_service" do
|
14
|
+
|
15
|
+
it "creates an instance" do
|
16
|
+
expect(subject.media_service).to_not be_nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "platform_lib/web_helper"
|
3
|
+
|
4
|
+
describe "Media Service" do
|
5
|
+
let(:data_service) do
|
6
|
+
service = PlatformLib::DataService.new("user", "pass")
|
7
|
+
service.stub(:sign_in)
|
8
|
+
service.stub(:sign_out)
|
9
|
+
service
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { data_service.media_service }
|
13
|
+
|
14
|
+
before do
|
15
|
+
subject.stub(:sign_in)
|
16
|
+
subject.stub(:sign_out)
|
17
|
+
end
|
18
|
+
|
19
|
+
it { should respond_to(:get_media_items) }
|
20
|
+
it { should respond_to(:update_media_items) }
|
21
|
+
|
22
|
+
describe "#get_media_items" do
|
23
|
+
before do
|
24
|
+
json_response = <<HEREDOC
|
25
|
+
{
|
26
|
+
"$xmlns": "http://somedomain.com/",
|
27
|
+
"entries": [
|
28
|
+
{
|
29
|
+
"id": "http://domain.com/id",
|
30
|
+
"title": "Item 1"
|
31
|
+
},
|
32
|
+
{
|
33
|
+
"id": "http://domain.com/id",
|
34
|
+
"title": "Item 2"
|
35
|
+
}
|
36
|
+
]
|
37
|
+
}
|
38
|
+
HEREDOC
|
39
|
+
|
40
|
+
PlatformLib::WebHelper.stub(:get).and_return(json_response)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns media items" do
|
44
|
+
expect(subject.get_media_items).to_not be_nil
|
45
|
+
end
|
46
|
+
|
47
|
+
it "executes block for each item" do
|
48
|
+
titles = []
|
49
|
+
subject.get_media_items do |item|
|
50
|
+
titles << item.title
|
51
|
+
end
|
52
|
+
|
53
|
+
expect(titles.size).to eq(2)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "spec_helper"
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
$: << File.expand_path("../../lib", __FILE__)
|
9
|
+
require "platform_lib"
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
config.filter_run :focus
|
15
|
+
|
16
|
+
# Run specs in random order to surface order dependencies. If you find an
|
17
|
+
# order dependency and want to debug it, you can fix the order by providing
|
18
|
+
# the seed, which is printed after each run.
|
19
|
+
# --seed 1234
|
20
|
+
config.order = 'random'
|
21
|
+
end
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: platform_lib
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Muto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hashie
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: tomdoc
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Simple library for working with ThePlatform Data Services
|
112
|
+
email:
|
113
|
+
- david.muto@shawmedia.ca
|
114
|
+
executables:
|
115
|
+
- tp_lib
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- .gitignore
|
120
|
+
- .rspec
|
121
|
+
- .travis.yml
|
122
|
+
- Gemfile
|
123
|
+
- Guardfile
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/tp_lib
|
128
|
+
- lib/platform_lib.rb
|
129
|
+
- lib/platform_lib/data_service.rb
|
130
|
+
- lib/platform_lib/media_service.rb
|
131
|
+
- lib/platform_lib/service_base.rb
|
132
|
+
- lib/platform_lib/task_service.rb
|
133
|
+
- lib/platform_lib/version.rb
|
134
|
+
- lib/platform_lib/web_helper.rb
|
135
|
+
- lib/scripts/sync_guid_with_id.rb
|
136
|
+
- platform_lib_ruby.gemspec
|
137
|
+
- spec/lib/platform_lib/data_service_spec.rb
|
138
|
+
- spec/lib/platform_lib/media_service_spec.rb
|
139
|
+
- spec/lib/scripts/sync_guid_with_id_spec.rb
|
140
|
+
- spec/spec_helper.rb
|
141
|
+
- spec/support/service_support.rb
|
142
|
+
homepage: https://github.com/ShawONEX/platform_lib_ruby
|
143
|
+
licenses:
|
144
|
+
- MIT
|
145
|
+
metadata: {}
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - '>='
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
requirements: []
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 2.2.1
|
163
|
+
signing_key:
|
164
|
+
specification_version: 4
|
165
|
+
summary: Work with ThePlatform Data Services
|
166
|
+
test_files:
|
167
|
+
- spec/lib/platform_lib/data_service_spec.rb
|
168
|
+
- spec/lib/platform_lib/media_service_spec.rb
|
169
|
+
- spec/lib/scripts/sync_guid_with_id_spec.rb
|
170
|
+
- spec/spec_helper.rb
|
171
|
+
- spec/support/service_support.rb
|