tpdata 0.9.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.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source :rubygems
2
+
3
+ gem 'httparty'
4
+
5
+ # Testing
6
+ group :test do
7
+ gem 'rspec'
8
+ gem 'ZenTest'
9
+ gem 'autotest-growl'
10
+ gem 'autotest-fsevent'
11
+ gem 'spork', '0.8.4'
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ ZenTest (4.8.1)
5
+ autotest-fsevent (0.2.8)
6
+ sys-uname
7
+ autotest-growl (0.2.16)
8
+ diff-lcs (1.1.3)
9
+ ffi (1.0.11)
10
+ httparty (0.8.3)
11
+ multi_json (~> 1.0)
12
+ multi_xml
13
+ multi_json (1.0.4)
14
+ multi_xml (0.5.1)
15
+ rspec (2.10.0)
16
+ rspec-core (~> 2.10.0)
17
+ rspec-expectations (~> 2.10.0)
18
+ rspec-mocks (~> 2.10.0)
19
+ rspec-core (2.10.1)
20
+ rspec-expectations (2.10.0)
21
+ diff-lcs (~> 1.1.3)
22
+ rspec-mocks (2.10.1)
23
+ spork (0.8.4)
24
+ sys-uname (0.9.0)
25
+ ffi (>= 1.0.0)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ ZenTest
32
+ autotest-fsevent
33
+ autotest-growl
34
+ httparty
35
+ rspec
36
+ spork (= 0.8.4)
data/Manifest.txt ADDED
@@ -0,0 +1,12 @@
1
+ Manifest.txt
2
+ README.markdown
3
+ Rakefile
4
+ bin/tpdata
5
+ lib/theplatform.rb
6
+ lib/theplatform/configuration.rb
7
+ lib/theplatform/data.rb
8
+ lib/theplatform/identity.rb
9
+ lib/theplatform/services.rb
10
+ spec/identity_spec.rb
11
+ spec/spec_helper.rb
12
+
data/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # tpdata
2
+
3
+ ## DESCRIPTION:
4
+
5
+ Tpdata gem is a wrapper for the RESTful interface for thePlatform for Media's Data Services.
6
+
7
+
8
+ ## REQUIREMENTS:
9
+
10
+ The only Gem requirement is HTTParty
11
+
12
+ ## INSTALL:
13
+
14
+ gem install tpdata
15
+
16
+ ## USAGE:
17
+
18
+ To add Tpdata gem:
19
+
20
+ require 'theplatform'
21
+
22
+ ### Configuration
23
+ Both endpoints (::Data and ::Identity) support the #configure methods to build instance variables on a per object basis.
24
+
25
+ ThePlatform::Data.configure do |config|
26
+ config.schema = '1.4.0'
27
+ config.form = 'cjson'
28
+ config.token = 'rDGZTYyxjGqjfEXNsphawfAqIdfdDDff'
29
+ end
30
+ => {:schema=>"1.4.0", :form=>"cjson", :token=>"rDGZTYyxjGqjfEXNsphawfAqIdfdDDff"}
31
+
32
+ To list the available params to configure:
33
+
34
+ ThePlatform::Identity.parameters
35
+ => {:schema=>"1.4.0", :form=>"cjson", :token=>"rDGZTYyxjGqjfEXNsphawfAqIdfdDDff"}
36
+
37
+ The boolean methods #parameters? is also available to query if all params are set:
38
+
39
+ ThePlatform::Identity.parameters?
40
+ => true
41
+
42
+ ### Tokens
43
+ To request a token:
44
+
45
+ ThePlatform::Identity.token(username:'your_username', password:'your_password',schema:'1.0',form:'json')
46
+ => {"signInResponse"=>
47
+ {"userName"=>"your_username",
48
+ "duration"=>315360000000,
49
+ "token"=>"rDGZTYyxjGqjfEXNsphawfAqIdfdDDff",
50
+ "userId"=>
51
+ "https://identity.auth.theplatform.com/idm/data/User/mps/123456789",
52
+ "idleTimeout"=>1209600000}}
53
+
54
+ Note that you can also set _duration and _idleTimeout as well. Visit http://help.theplatform.com for more information.
55
+
56
+ ### Data Services
57
+ A list of endpoints and valid objects are available at http://help.theplatform.com. Internally, they are listed in the services.rb file.
58
+
59
+ In this example, we're going to build a query for the Media Data Service (MDS):
60
+
61
+ media = ThePlatform::Data.mds
62
+ @endpoint="http://data.media.theplatform.com/media/data/",
63
+ @objects=
64
+ [:AccountSettings,
65
+ :AssetType,
66
+ :Category,
67
+ :Media,
68
+ :MediaDefaults,
69
+ :MediaFile,
70
+ :Provider,
71
+ :Release,
72
+ :Server]>
73
+
74
+ The return value for any Service Object is its endpoint and the available objects.
75
+ To build the query for a GET:
76
+
77
+ media.get('Category','12744085', schema:'1.4.0',form:'json',token:'12uZynnc2zHvVNDokvgG0TC9UBD7EPDm')
78
+
79
+ Needed parameters are the Objects, Object ID(s), Schema, Form, and the Token (which can be built through the ThePlatform::Identity)
80
+
81
+ To request all objects, pass 'all' to the id param. To return multiple objects, pass a String with comma separated IDs.
82
+
83
+ A POST:
84
+
85
+ media.post('Media', '{"title":"First POST using the RUBYds","ownerId":"http://access.auth.theplatform.com/data/Account/123456789"}',schema:'1.4.0',form:'cjson',token:'Nez8Y9ScVDxPxLDmUsg_ESCDYJCJwPBk',account:'My_Account')
86
+
87
+ Note that this is a JSON POST body, but is entered as a String object with a JSON body.
88
+
89
+ The same holds true for PUT values as well, media.put
90
+
91
+ A DELETE:
92
+
93
+ media.delete('Media','27550715', schema:'1.4.0',form:'cjson',token:'Nez8Y9ScVDxPxLDmUsg_ESCDYJCJwPBk',account:'My_Account')
94
+
95
+ Needed params here are the Object, Object ID(s), schema, form, token, and account.
96
+
97
+ ## ToDo:
98
+ * Add SELF to the Identity endpoints
99
+ * Unit::Tests and Specs for all. Use mocks instead of live data!
100
+
101
+ ## LICENSE:
102
+
103
+ Copyright (c) 2012 Ben Woodall
104
+
105
+ Code hosted at git://ln.benwoodall.com/tpdata.git as ReadOnly.
106
+ For Write access or send-email diffs: mail@benwoodall.com
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc "Run specs"
6
+ RSpec::Core::RakeTask.new do |t|
7
+ t.pattern = './spec/*/*_spec.rb'
8
+ end
9
+
10
+ task default: :spec
data/bin/tpdata ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ abort "you need to write me"
@@ -0,0 +1,14 @@
1
+ require './lib/theplatform.rb'
2
+
3
+ # request a new token!
4
+ token = ThePlatform::Identity.token(username:'my_username',password:'my_password',schema:'1.0',form:'json')
5
+
6
+ # use #configure to build a basic request
7
+ ThePlatform::Data.configure do |c|
8
+ c.schema='1.4.0'
9
+ c.form='cjson'
10
+ c.token=token['signInResponse']['token']
11
+ end
12
+
13
+ # return all the Categories!
14
+ puts ThePlatform::Data.mds.get('Category','all',account:'my_account')
@@ -0,0 +1,44 @@
1
+ module ThePlatform
2
+
3
+ # Module to extend to other Classes in order to set up #configuration on a per object basis
4
+ module Configuration
5
+
6
+ extend self
7
+
8
+ attr_accessor :schema, :form, :token, :username, :password, :_duration, :_idleTimeout
9
+
10
+ # Allows for a Rails type configuration setup. Different object make different configurations.
11
+ #
12
+ # ThePlatform::Data.configure do |config|
13
+ # config.schema = '1.4.0'
14
+ # config.form = 'cjson'
15
+ # config.token = 'o4VThP--IcaKwltckmgdw544KD0kKDg'
16
+ # end
17
+ # => {:schema=>"1.4.0", :form=>"json", :token=>"o4VThP--IcaKwltckmgdw544KD0kKDg"}
18
+ #
19
+ def configure
20
+ yield self
21
+ parameters
22
+ end
23
+
24
+ # List available parameters and values in those params
25
+ def parameters
26
+ @values = {}
27
+ keys.each { |k| @values.merge! k => get_var("@#{k}") }
28
+ @values
29
+ end
30
+
31
+ # Returns true or false if all parameters are set.
32
+ def parameters?
33
+ parameters.values.all?
34
+ end
35
+
36
+ private
37
+
38
+ # Helper to clean up recursive method in #parameters
39
+ def get_var(var)
40
+ self.instance_variable_get(var)
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,120 @@
1
+ module ThePlatform
2
+
3
+ # Class to RESTfully interface with thePlatform's API
4
+ # ThePlatform::Data#
5
+ class Data
6
+ include HTTParty
7
+ extend ThePlatform::Configuration
8
+
9
+ def initialize(params={})
10
+ @endpoint = params[:endpoint]
11
+ @objects = params[:objects]
12
+ end
13
+
14
+ # Set the different available params to configure
15
+ def self.keys
16
+ @keys ||= [:schema, :form, :token]
17
+ end
18
+
19
+ # MetaMagic to initialize SERVICE hash into methods to create SERVICE objects
20
+ (class << self; self; end).instance_eval do
21
+ SERVICE.keys.each do |data|
22
+ define_method(data) { self.new(endpoint: SERVICE[data][:endpoint], objects: SERVICE[data][:objects]) }
23
+ end
24
+ end
25
+
26
+ # GET call for data Object.
27
+ #
28
+ # This is built by passing the Object, the comma delimited IDs, and the RESTful parameters.
29
+ # To return all the Objects, pass 'all' for the id param.
30
+ #
31
+ # Needed paramters are: schema, form, and token
32
+ #
33
+ # ThePlatform::Data.mds.get('Category','1278889',schema:'1.4.0',form:'json',token:'12uZynnc2zHvVNDokvgG0mmK33yOOd',account:'my_account')
34
+ # or
35
+ # ThePlatform::Data.mds.get('Category','all',schema:'1.4.0',form:'json',token:'12uZynnc2zHvVNDokvgG0mmK33yOOd',account:'my_account')
36
+ def get(object, id=[],options={})
37
+ set_uri
38
+ set_id = "/#{id}" unless id =~ /all/i
39
+ self.class.get("/#{object}#{set_id}", query: extras.merge(options))
40
+ end
41
+
42
+ # POST to create new Objects.
43
+ #
44
+ # Posts are created by passing the Object type, and a String object of the POST body.
45
+ #
46
+ # Needed parameters are: schema, form, token, and account.
47
+ #
48
+ # the_body = '{'title':'Using the RUBYds',"ownerId":"http://access.auth.theplatform.com/data/Account/2011111628"}'
49
+ # ThePlatform::Data.mds.put('Media', the_body,
50
+ # schema:'1.4.0',form:'cjson',token:'Nez8Y9ScVDxPxLDmUsg_ESCDYJCJwPBk',account:'Ruby Test Account')
51
+ def post(object, body, options={})
52
+ set_uri
53
+ set_header options
54
+ self.class.post("/#{object}", query: extras.merge(options), body: body)
55
+ end
56
+
57
+ # PUT to edit Objects.
58
+ #
59
+ # Put needs the Object type and String body.
60
+ #
61
+ # Needed parameters: schema, form, token, and account.
62
+ #
63
+ # the_body = '{"id":""http://data.media.theplatform.com/media/data/Media/27444715"","title":"test"}'
64
+ # ThePlatform::Data.mds.put('Media', the_body,
65
+ # schema:'1.4.0',form:'cjson',token:'Nez8Y9ScVDxPxLDmUsg_ESCDYJCJwPBk',account:'Ruby Test Account')
66
+ def put(object, body, options={})
67
+ set_uri
68
+ set_header options
69
+ self.class.put("/#{object}", query: extras.merge(options), body: body)
70
+ end
71
+
72
+ # DELETE objects
73
+ #
74
+ # To DELETE Objects, pass the Object type and comma separated IDs
75
+ #
76
+ # Needed parameters: schema, form, token, and account
77
+ #
78
+ # ThePlatform::Data.mds.delete('Media','27550715', schema:'1.4.0',form:'cjson',
79
+ # token:'Nez8Y9ScVDxPxLDmUsg_ESCDYJCJwPBk',account:'Ruby Test Account')
80
+ def delete(object,id=[],options={})
81
+ set_uri
82
+ self.class.delete("/#{object}/#{id}", query: extras.merge(options))
83
+ end
84
+
85
+ # NOTIFY endpoint
86
+ #
87
+ # This moves to the /notify endpoint of the data service
88
+ #
89
+ # Needed parameters: token
90
+ #
91
+ # ThePlatform::Data.mds.notify(token:'G1yP1Zsp7nEHW2fug6glIQCjfjIIIl', size:'10', since:'289334341')
92
+ def notify(options={})
93
+ self.class.base_uri @endpoint
94
+ self.class.get("/notify", query: options)
95
+ end
96
+
97
+ private
98
+
99
+ def set_header(option)
100
+ if option[:form] == 'json'
101
+ self.class.headers 'Content-Type' => 'application/json'
102
+ elsif option[:form] == 'atom'
103
+ self.class.headers 'Content-Type' => 'application/atom+xml'
104
+ elsif option[:form] == 'rss'
105
+ self.class.headers 'Content-Type' => 'application/rss+xml'
106
+ end
107
+
108
+ end
109
+
110
+ def extras
111
+ ThePlatform::Data.parameters
112
+ end
113
+
114
+ def set_uri
115
+ self.class.base_uri "#{@endpoint}data/"
116
+ end
117
+
118
+ end
119
+
120
+ end
@@ -0,0 +1,52 @@
1
+ module ThePlatform
2
+
3
+ # Class to RESTfully interface with thePlatform's Identity API
4
+ # ThePlatform::Identity#
5
+ class Identity
6
+ include HTTParty
7
+ extend ThePlatform::Configuration
8
+
9
+ class << self
10
+
11
+ # Set the different available params to configure
12
+ def keys
13
+ @keys ||= [:schema, :form, :username, :password, :_duration, :_idleTimeout]
14
+ end
15
+
16
+ # Return ALL THE TOKEN!
17
+ #
18
+ # ThePlatform::Identity.token(username:'USERNAME', password:'PASSWORD', schema:'1.0', form:'(json|xml|rss)')
19
+ #
20
+ # _duration: and _idleTimeout: are optional. Resorts to thePlatform defaults if not defined
21
+ def token(options = {})
22
+ base_uri IDENTITY
23
+ get("/signIn", query: extras.merge(options))
24
+ end
25
+
26
+ # Invalidate a given Token
27
+ #
28
+ # ThePlatform::Identity.invalidate!(token, schema:'1.0', form:'(json|xml|rss)')
29
+ def invalidate!(tokens, options = {})
30
+ base_uri IDENTITY
31
+ get("/signOut?_token=#{tokens}", query: extras.merge(options))
32
+ end
33
+
34
+ # Return the number of tokens in an account.
35
+ #
36
+ # ThePlatform::Identity.count(username:'USERNAME', password:'PASSWORD',schema:'1.0', form:'(json|xml|rss)')
37
+ def count(options = {})
38
+ base_uri IDENTITY
39
+ get("/getTokenCount", query: extras.merge(options))
40
+ end
41
+
42
+ end
43
+
44
+ private
45
+
46
+ def self.extras
47
+ ThePlatform::Identity.parameters
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,60 @@
1
+ module ThePlatform
2
+
3
+ # URI for Identity service
4
+ IDENTITY = "https://identity.auth.theplatform.com/idm/web/Authentication/"
5
+
6
+ # Hash containing Data Services, along with their available objects
7
+ SERVICE =
8
+ {
9
+ :accessadmin => { :endpoint => 'http://access.auth.theplatform.com/',
10
+ :objects => [ :Account, :Permission, :Registry, :Role ] },
11
+ :enduser => { :endpoint => 'http://enduser.access.auth.theplatform.com/',
12
+ :objects => [ :Permission, :Role ] },
13
+ :console => { :endpoint => 'http://data.mpx.theplatform.com/cds/',
14
+ :objects => [ :AccountSettings, :Command, :MenuItem, :Pane, :PaneState, :Panel,
15
+ :Shortcut, :UserAccountSettings, :UserSettings, :View, :ViewLink ] },
16
+ :delivery => { :endpoint => 'http://data.delivery.theplatform.com/delivery/',
17
+ :objects => [ :AccountSettings, :AdPolicy, :Restriction ] },
18
+ :entitlements => { :endpoint => 'http://data.entitlement.theplatform.com/eds/',
19
+ :objects => [ :AccountSettings, :Device, :DistributionRights, :Entitlement,
20
+ :PhysicalDevice, :ProductDevice, :Rights, :SubjectPolicy, :UserDevice ] },
21
+ :feedreader => { :endpoint => 'http://feedreader.ingest.theplatform.com/feedreader/',
22
+ :objects => [ :FeedReader ] },
23
+ :feeds => { :endpoint => 'http://data.feed.theplatform.com/feed/',
24
+ :objects => [ :FeedAdapter, :FeedConfig ] },
25
+ :ingest => { :endpoint => 'http://adapter.ingest.theplatform.com/adapter/',
26
+ :objects => [ :Adapter, :AdapterConfiguration, :Checksum ] },
27
+ :mds => { :endpoint => 'http://data.media.theplatform.com/media/',
28
+ :objects => [ :AccountSettings, :AssetType, :Category, :Media,
29
+ :MediaDefaults, :MediaFile, :Provider, :Release, :Server ] },
30
+ :mps => { :endpoint => 'http://mps.theplatform.com/',
31
+ :objects => [ :Account, :AssetType, :Batch, :Category, :DefaultServer, :Media,
32
+ :MediaFile, :MediaRequest, :Release, :Server, :Task ]},
33
+ :message => { :endpoint => 'http://data.message.theplatform.com/message/',
34
+ :objects => [ :EmailTemplate, :MessageInstruction, :MessageQueue, :NotificationFilter ] },
35
+ :product => { :endpoint => 'http://data.product.theplatform.com/product/',
36
+ :objects => [ :AccountSettings, :PricingTemplate, :Product, :ProductTag ] },
37
+ :publish => { :endpoint => 'http://data.publish.theplatform.com/publish/',
38
+ :objects => [ :Adapter, :AdapterConfiguration, :PublishProfile ] },
39
+ :sharing => { :endpoint => 'http://data.social.community.theplatform.com/social/',
40
+ :objects => [ :OutletProfile, :ProviderAdapter ] },
41
+ :social => { :endpoint => 'http://data.social.community.theplatform.com/social/',
42
+ :objects => [ :AccountSettings, :Comment, :Rating, :TotalRating ] },
43
+ :task => { :endpoint => 'http://data.task.theplatform.com/task/',
44
+ :objects => [ :Agent, :Batch, :Task, :TaskTemplate, :TaskType ] },
45
+ :identity => { :endpoint => 'https://identity.auth.theplatform.com/idm/',
46
+ :objects => [ :Directory, :Security, :User ] },
47
+ :euid => { :endpoint => 'https://euid.theplatform.com/idm/',
48
+ :objects => [ :Directory, :Security, :User ] },
49
+ :userprofile => { :endpoint => 'http://data.userprofile.community.theplatform.com/userprofile/',
50
+ :objects => [ :AccountSettings, :TotalItem, :UserList,
51
+ :UserListItem, :UserProfile ] },
52
+ :validation => { :endpoint => 'http://data.validation.theplatform.com/validation/',
53
+ :objects => [ :ConditionsRule, :ValidationRule, :Validator ] },
54
+ :watchfolder => { :endpoint => 'http://watchfolder.ingest.theplatform.com/wf/',
55
+ :objects => [ :WatchFolder, :WatchFolderFile ] },
56
+ :workflow => { :endpoint => 'http://data.workflow.theplatform.com/workflow/',
57
+ :objects => [ :ProfileResult, :ProfileStepResult, :WorkflowQueue ] }
58
+ }
59
+
60
+ end
@@ -0,0 +1,16 @@
1
+ $:.unshift( File.dirname( __FILE__ ))
2
+
3
+ require 'httparty'
4
+
5
+ # Start of wrapper for tpdata
6
+ module ThePlatform
7
+
8
+ # Set gem version
9
+ VERSION = '0.9.1'
10
+
11
+ require 'theplatform/configuration'
12
+ require 'theplatform/services'
13
+ require 'theplatform/identity'
14
+ require 'theplatform/data'
15
+
16
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThePlatform::Configuration do
4
+
5
+ describe 'mass configuration' do
6
+
7
+ before do
8
+ ThePlatform::Data.configure do |config|
9
+ config.schema = '1.4.0'
10
+ config.form = 'cjson'
11
+ config.token = 'my_token'
12
+ end
13
+ end
14
+
15
+ it 'should set instance variables' do
16
+ ThePlatform::Data.parameters[:schema].should == '1.4.0'
17
+ ThePlatform::Data.parameters[:form].should == 'cjson'
18
+ ThePlatform::Data.parameters[:token].should == 'my_token'
19
+ end
20
+
21
+ it 'should return true if all values are set' do
22
+ ThePlatform::Data.parameters?.should be true
23
+ end
24
+
25
+ it 'should return false if all values are not set' do
26
+ ThePlatform::Data.schema = nil
27
+ ThePlatform::Data.parameters[:schema].should == nil
28
+ ThePlatform::Data.parameters?.should be false
29
+ end
30
+
31
+ end
32
+
33
+ describe 'endpoints' do
34
+
35
+ it 'should list correct keys for ::Data' do
36
+ ThePlatform::Data.keys.should == [:schema, :form, :token]
37
+ end
38
+
39
+ it 'should list correct keys for ::Identity' do
40
+ ThePlatform::Identity.keys.should == [:schema, :form, :username, :password, :_duration, :_idleTimeout]
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThePlatform::Data do
4
+
5
+ describe 'default attributes' do
6
+
7
+ it 'should include HTTParty methods' do
8
+ ThePlatform::Data.should include HTTParty
9
+ end
10
+
11
+ end
12
+
13
+ describe 'endpoints' do
14
+
15
+ it 'should make for new class methods' do
16
+ ThePlatform.const_get(:SERVICE).keys.each do |endpoint|
17
+ ThePlatform::Data.methods.should include endpoint
18
+ end
19
+ end
20
+
21
+ it 'should return a list of available data service objects' do
22
+ ThePlatform.const_get(:SERVICE).keys.each do |endpoint|
23
+ ThePlatform.const_get(:SERVICE).values_at(endpoint)[0].keys.should include :objects
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ describe 'requests' do
30
+
31
+ it 'should return 200' do
32
+ ThePlatform.const_get(:SERVICE).keys.each do |endpoint|
33
+ ThePlatform::Data.send(endpoint).get('', 'all', schema:'1.0', form:'json').code.should == 200
34
+ end
35
+ end
36
+
37
+ it 'should make a GET against an endpoint' do
38
+ ThePlatform.const_get(:SERVICE).keys.each do |endpoint|
39
+ ThePlatform::Data.send(endpoint).get('Object', 'all').request.instance_variable_get(:@http_method).should equal Net::HTTP::Get
40
+ end
41
+ end
42
+
43
+ it 'should make a POST against an endpoint' do
44
+ ThePlatform.const_get(:SERVICE).keys.each do |endpoint|
45
+ ThePlatform::Data.send(endpoint).post('Object', '{BODY}').request.instance_variable_get(:@http_method).should equal Net::HTTP::Post
46
+ end
47
+ end
48
+
49
+ it 'should make a PUT against an endpoint' do
50
+ ThePlatform.const_get(:SERVICE).keys.each do |endpoint|
51
+ ThePlatform::Data.send(endpoint).put('Object', '{BODY}').request.instance_variable_get(:@http_method).should equal Net::HTTP::Put
52
+ end
53
+ end
54
+
55
+ it 'should make a DELETE against an endpoint' do
56
+ ThePlatform.const_get(:SERVICE).keys.each do |endpoint|
57
+ ThePlatform::Data.send(endpoint).delete('Object', 'IDS').request.instance_variable_get(:@http_method).should equal Net::HTTP::Delete
58
+ end
59
+ end
60
+
61
+ it 'should be able to use the NOTIFY method' do
62
+ ThePlatform.const_get(:SERVICE).keys.each do |endpoint|
63
+ ThePlatform::Data.send(endpoint).notify('options').request.instance_variable_get(:@http_method).should equal Net::HTTP::Get
64
+ end
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThePlatform::Identity do
4
+
5
+ describe 'default attributes' do
6
+
7
+ it 'should include HTTParty methods' do
8
+ ThePlatform::Identity.should include HTTParty
9
+ end
10
+
11
+ end
12
+
13
+ describe "#token" do
14
+
15
+ it "should return a 200 response" do
16
+ ThePlatform::Identity.token(form:'json', schema:'1.0').code.should == 200
17
+ end
18
+
19
+ it 'should return BAD REQUEST if no schema or form present' do
20
+ ThePlatform::Identity.token(test:1, test:2).code.should == 422
21
+ end
22
+
23
+ it 'should have a valid return body' do
24
+ ThePlatform::Identity.token(form:'json', schema:'1.0')['description'].should == "No authentication header."
25
+ end
26
+
27
+ it 'should not authenticate an invalid user' do
28
+ ThePlatform::Identity.token(form:'json', schema:'1.0', username:'test', password:'pass')['description'].should == "Could not authenticate user test."
29
+ end
30
+ end
31
+
32
+ describe "#invalidate!" do
33
+
34
+ it 'should return a 200 response' do
35
+ ThePlatform::Identity.invalidate!('omg_i_haz_a_tokenz', form:'json', schema:'1.0').code.should == 200
36
+ end
37
+
38
+ it 'should have a valid return body' do
39
+ ThePlatform::Identity.invalidate!('omg_i_haz_a_tokenz', form:'json', schema:'1.0').should have_key 'signOutResponse'
40
+ end
41
+
42
+ end
43
+
44
+ describe "#count" do
45
+
46
+ it "should return a 200 response" do
47
+ ThePlatform::Identity.count(form:'json', schema:'1.0').code.should == 200
48
+ end
49
+
50
+ it 'should return a BAD REQUEST if no schema or form are present' do
51
+ ThePlatform::Identity.count(test:1, test:2).code.should == 422
52
+ end
53
+
54
+ it 'should fail if auth is invalid' do
55
+ ThePlatform::Identity.count(form:'json', schema:'1.0', username:'test', password:'pass')['description'].should == "Could not authenticate user test."
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+
4
+ require File.expand_path("../../lib/theplatform", __FILE__)
@@ -0,0 +1,25 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require './lib/theplatform.rb'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'tpdata'
6
+ s.version = ThePlatform::VERSION
7
+ s.date = '2012-09-28'
8
+ s.authors = ['Ben Woodall']
9
+ s.email = 'ben.woodall@theplatform.com'
10
+ s.homepage = 'http://github.com/benwoody/tpdata'
11
+
12
+ s.summary = %q{RESTful wrapper for thePlatform}
13
+ s.description = %q{Tpdata gem is a wrapper for the RESTful interface for thePlatform for Media's Data Services.}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.require_paths = ["lib"]
18
+
19
+ s.extra_rdoc_files = ["README.md"]
20
+
21
+ s.add_runtime_dependency 'httparty', "~> 0.8.3"
22
+ s.add_development_dependency 'rake'
23
+ s.add_development_dependency 'rspec'
24
+ s.add_development_dependency 'yard'
25
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tpdata
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ben Woodall
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.8.3
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: yard
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Tpdata gem is a wrapper for the RESTful interface for thePlatform for
79
+ Media's Data Services.
80
+ email: ben.woodall@theplatform.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files:
84
+ - README.md
85
+ files:
86
+ - Gemfile
87
+ - Gemfile.lock
88
+ - Manifest.txt
89
+ - README.md
90
+ - Rakefile
91
+ - bin/tpdata
92
+ - examples/data_example.rb
93
+ - lib/theplatform.rb
94
+ - lib/theplatform/configuration.rb
95
+ - lib/theplatform/data.rb
96
+ - lib/theplatform/identity.rb
97
+ - lib/theplatform/services.rb
98
+ - spec/lib/configuration_spec.rb
99
+ - spec/lib/data_spec.rb
100
+ - spec/lib/identity_spec.rb
101
+ - spec/spec_helper.rb
102
+ - theplatform.gemspec
103
+ homepage: http://github.com/benwoody/tpdata
104
+ licenses: []
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 1.8.21
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: RESTful wrapper for thePlatform
127
+ test_files:
128
+ - spec/lib/configuration_spec.rb
129
+ - spec/lib/data_spec.rb
130
+ - spec/lib/identity_spec.rb
131
+ - spec/spec_helper.rb
132
+ has_rdoc: