scripted_client 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 60bbca440d11c0a5cc9df900fd46e73f09e2026b
4
+ data.tar.gz: 3afa43ce47b97c7507d063be64df2c63d8dc2ae7
5
+ SHA512:
6
+ metadata.gz: 05cf9bcbc9764b0084f88501d87a796167394f30bc396fcfafb1dd08d6beb436e542545082bdedfe220110e8d79e615dea06c6e3308d9c7fb8a351fe780a3bfa
7
+ data.tar.gz: 1458ae1a84310c1a07ede9dca83aa7cabb4c0c0a46c22a0f3234f5cff251a520a1e165d08becdccf1329f6402e93ce0103b03cf29fb0433f9c835bb26b1d4a77
@@ -0,0 +1,100 @@
1
+ # The Scripted API Client
2
+
3
+ ### Setup
4
+
5
+ Install via RubyGems:
6
+
7
+ gem install scripted_client
8
+
9
+ Or a Gemfile:
10
+
11
+ gem 'scripted_client'
12
+
13
+ In an initializer, set up your account organization_key and access token. For example:
14
+
15
+ # config/initializers/scripted.rb
16
+ ScriptedClient.organization_key = 'orangutan'
17
+ ScriptedClient.access_token = 'make-great-pets'
18
+
19
+ In production, make sure you set the environment to **:production**
20
+
21
+ ScriptedClient.env = :production
22
+
23
+ Otherwise, it will be **:sandbox** by default. Contact us for a Sandbox Account!
24
+
25
+ ### Creating a Job
26
+
27
+ First, find a JobTemplate that you'd like to use:
28
+
29
+ templates = ScriptedClient::JobTemplate.all
30
+ blog_post = templates.find { |template| template.name == 'Standard Blog Post' }
31
+
32
+ Next, assign some values for the Prompts on that JobTemplate. Prompts are question/answer pairs that help guorganization_keye your writer. They can be one of five kinds: `string[255]` `string[1024]` `radio` `checkbox` `array`. The data type of the `value` that you post will depend on the kind of the Prompt:
33
+
34
+ | Kind | Value Type | Has `value_options`? |
35
+ |--------------|-------------------------------|----------------------|
36
+ | string[255] | String (max. 255 characters) | No |
37
+ | string[1024] | String (max. 1024 characters) | No |
38
+ | radio | String | Yes |
39
+ | checkbox | Array | Yes |
40
+ | array | Array | No |
41
+
42
+ If the prompt has `value_options` the `value` you pick has to be one of them.
43
+
44
+ Here's how you might update a couple of prompt values:
45
+
46
+ sample_blog = blog_post.prompts.find { |prompt| prompt.label == 'Sample Blog' }
47
+ sample_blog.value = 'https://scripted.com/blogs/'
48
+ goal = blog_post.prompts.find { |prompt| prompt.label == 'Goal' }
49
+ goal.value = ['Informed analysis']
50
+ key_points = blog_post.prompts.find { |prompt| prompt.label == 'Key Points' }
51
+ key_points.value = ['Orangutans make great pets', 'Normal pets are lame']
52
+
53
+ Next, you can find an Industry:
54
+
55
+ industries = ScriptedClient::Industry.all
56
+ lifestyle = industries.find { |industry| industry.name == 'Lifestyle & Travel' }
57
+
58
+ Now you can create the Job!
59
+
60
+ job = ScriptedClient::Job.new(
61
+ topic: 'Top 10 Reasons to Buy an Orangutan',
62
+ job_template: blog_post,
63
+ industries: [lifestyle]
64
+ )
65
+ job.save
66
+ # => true
67
+
68
+ **Protip** If `job.save` returns `false` use `job.errors.full_messages` to see what went wrong.
69
+
70
+ ### Retrieving Jobs
71
+
72
+ Get all jobs using `ScriptedClient::Job.all`, or be a bit more specific using any of these scopes:
73
+
74
+ screening writing draft_ready revising final_ready in_progress needs_review accepted rejected finished
75
+
76
+ For example:
77
+
78
+ jobs = ScriptedClient::Job.needs_review
79
+
80
+ There are also scopes on Pitchset: `open`, `closed` and `requires_action`.
81
+
82
+ If the collection has a next page:
83
+
84
+ jobs = ScriptedClient::Job.all
85
+ jobs.has_next?
86
+ # => true
87
+
88
+ you can retrieve that next page using `next`:
89
+
90
+ jobs = ScriptedClient::Job.all
91
+ page_two = jobs.next
92
+
93
+ If you'd like to review the written content itself, use the `html_contents` method:
94
+
95
+ job = ScriptedClient::Job.first
96
+ job.html_contents
97
+
98
+ ### Development
99
+
100
+ From within this directory, `bundle install` and run `rspec` to execute the tests. If you want to use the gem against a local version of the API, set `ScriptedClient.env = :development`.
@@ -0,0 +1,79 @@
1
+ module ScriptedClient
2
+ API_VERSION = 'v1'
3
+ @@access_token, @@organization_key = nil, nil
4
+ @@env = :sandbox
5
+
6
+ def self.access_token
7
+ @@access_token || fail("You must set #{ name }.access_token")
8
+ end
9
+
10
+ def self.access_token=(_access_token)
11
+ @@access_token = _access_token
12
+ reset_resource_site
13
+ @@access_token
14
+ end
15
+
16
+ def self.organization_key
17
+ @@organization_key || fail("You must set #{ name }.organization_key")
18
+ end
19
+
20
+ def self.organization_key=(_organization_key)
21
+ @@organization_key = _organization_key
22
+ reset_resource_site
23
+ @@organization_key
24
+ end
25
+
26
+ def self.env
27
+ @@env
28
+ end
29
+
30
+ def self.env=(_env)
31
+ unless [:development, :sandbox, :production].include?(_env)
32
+ fail "#{ name }.env must be either :sandbox or :production"
33
+ end
34
+ @@env = _env
35
+ reset_resource_site
36
+ @@env
37
+ end
38
+
39
+ def self.base_host
40
+ case env
41
+ when :sandbox
42
+ 'scripted-sandbox.herokuapp.com'
43
+ when :production
44
+ 'api.scripted.com'
45
+ when :development
46
+ 'localhost:3000'
47
+ end
48
+ end
49
+
50
+ def self.protocol
51
+ env == :development ? 'http' : 'https'
52
+ end
53
+
54
+ def self.base_url
55
+ "#{ protocol }://#{ base_host }"
56
+ end
57
+
58
+ def self.prefix
59
+ "/#{ organization_key }/#{ API_VERSION }/"
60
+ end
61
+
62
+ def self.reset_resource_site
63
+ if @@organization_key && @@access_token
64
+ ScriptedClient::Resource.site = base_url
65
+ ScriptedClient::Resource.prefix = prefix
66
+ ScriptedClient::Resource.descendants.each(&:setup_prefix)
67
+ ScriptedClient::Resource.headers['Authorization'] = "Bearer #{ access_token }"
68
+ end
69
+ end
70
+ end
71
+
72
+ require 'active_resource'
73
+ require 'scripted_client/collection'
74
+ require 'scripted_client/resource'
75
+ require 'scripted_client/job'
76
+ require 'scripted_client/job_template'
77
+ require 'scripted_client/industry'
78
+ require 'scripted_client/pitch'
79
+ require 'scripted_client/pitchset'
@@ -0,0 +1,24 @@
1
+ module ScriptedClient
2
+ class Collection < ActiveResource::Collection
3
+
4
+ attr_accessor :next_page
5
+
6
+ def initialize(parsed = {})
7
+ @elements = parsed['data']
8
+ paging = parsed['paging']
9
+ @next_page = paging['next_cursor'] if paging && paging['has_next']
10
+ end
11
+
12
+ def next
13
+ fail 'No more pages' unless has_next?
14
+ resource_class.all(
15
+ params: original_params.merge(next_cursor: next_page)
16
+ )
17
+ end
18
+
19
+ def has_next?
20
+ next_page.present?
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ module ScriptedClient
2
+ class Industry < Resource
3
+
4
+ # Caching because industries never change
5
+ def self.all(*args)
6
+ @@all ||= super
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ module ScriptedClient
2
+ class Job < Resource
3
+ define_filter_methods(%w(
4
+ screening
5
+ writing
6
+ draft_ready
7
+ revising
8
+ final_ready
9
+ in_progress
10
+ needs_review
11
+ accepted
12
+ rejected
13
+ finished))
14
+
15
+ def html_contents
16
+ get(:html_contents)['html_contents']
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ module ScriptedClient
2
+ class JobTemplate < Resource
3
+ end
4
+ end
@@ -0,0 +1,36 @@
1
+ module ScriptedClient
2
+ class Pitch < Resource
3
+ def self.find(*arguments)
4
+ if arguments.first.kind_of?(String)
5
+ options = arguments[1]
6
+ unless options.kind_of?(Hash) &&
7
+ options[:params].kind_of?(Hash) &&
8
+ options[:params].key?(:pitchset_id)
9
+ fail "You must pass both a pitchset_id and an id to #{ name }#find. For example: \n
10
+ #{ name }.find('#{ arguments.first }', params: { pitchset_id: 'abc123' }) \n\n\n"
11
+ end
12
+ end
13
+ super
14
+ end
15
+
16
+ def self.setup_prefix
17
+ self.prefix = "#{ prefix }pitchsets/:pitchset_id/"
18
+ end
19
+
20
+ def accept(feedback = nil)
21
+ set_pitchset_prefix
22
+ post(:accept, {}, { feedback: feedback }.to_json)
23
+ end
24
+
25
+ def reject(feedback = nil)
26
+ set_pitchset_prefix
27
+ post(:reject, {}, { feedback: feedback }.to_json)
28
+ end
29
+
30
+ private
31
+
32
+ def set_pitchset_prefix
33
+ self.prefix_options[:pitchset_id] = pitchset.id
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,6 @@
1
+ module ScriptedClient
2
+ class Pitchset < Resource
3
+ define_filter_methods(%w(open closed requires_action))
4
+ has_many :pitches, class_name: 'scripted_client/pitch'
5
+ end
6
+ end
@@ -0,0 +1,26 @@
1
+ module ScriptedClient
2
+ class Resource < ActiveResource::Base
3
+ self.format = :json
4
+ self.collection_parser = ScriptedClient::Collection
5
+
6
+ # Some tasteful meta-programming to define
7
+ # filter methods, for example:
8
+ ### ScriptedClient::Job.needs_review
9
+ def self.define_filter_methods(filters)
10
+ filters.each do |filter|
11
+ define_singleton_method(filter) do
12
+ all(params: { filter: filter })
13
+ end
14
+ end
15
+ end
16
+
17
+ def self.site
18
+ super if ScriptedClient.organization_key && ScriptedClient.access_token
19
+ end
20
+
21
+ # A hook for any nested resources
22
+ # (see ScriptedClient::Pitch for implementation)
23
+ def self.setup_prefix; end
24
+
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scripted_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Jake Kring
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activeresource
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.3.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 3.3.0
41
+ description: Provides a simple wrapper for creating, listing and reviewing Scripted.com
42
+ Jobs and Pitches.
43
+ email: jake@scripted.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - README.md
49
+ - lib/scripted_client.rb
50
+ - lib/scripted_client/collection.rb
51
+ - lib/scripted_client/industry.rb
52
+ - lib/scripted_client/job.rb
53
+ - lib/scripted_client/job_template.rb
54
+ - lib/scripted_client/pitch.rb
55
+ - lib/scripted_client/pitchset.rb
56
+ - lib/scripted_client/resource.rb
57
+ homepage: http://rubygems.org/gems/scripted_client
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.2.2
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: A client to consume the Scripted.com API
81
+ test_files: []