Skip to content

Commit

Permalink
Merge pull request #7 from rgraff/master
Browse files Browse the repository at this point in the history
Add all missing API commands
  • Loading branch information
mattfawcett committed Nov 4, 2014
2 parents 544965b + 834de3a commit 840338f
Show file tree
Hide file tree
Showing 18 changed files with 424 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .rspec
@@ -1 +1 @@
--tty --colour --profile --format nested
--tty --colour --profile
14 changes: 14 additions & 0 deletions Gemfile
@@ -0,0 +1,14 @@
source "http://rubygems.org"

gem "httparty", ">= 0.6.1"

group :development do
gem "rspec"
gem "bundler", "~> 1.0"
gem "jeweler", "~> 2.0.1"
gem "simplecov", ">= 0"
gem "fakeweb"
gem 'guard-rspec', '~> 4.3.1'
gem 'guard-bundler'
gem 'terminal-notifier-guard'
end
118 changes: 118 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,118 @@
GEM
remote: http://rubygems.org/
specs:
addressable (2.3.6)
builder (3.2.2)
celluloid (0.15.2)
timers (~> 1.1.0)
coderay (1.1.0)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
diff-lcs (1.2.5)
docile (1.1.5)
fakeweb (1.3.0)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
ffi (1.9.3)
formatador (0.2.5)
git (1.2.8)
github_api (0.12.1)
addressable (~> 2.3)
descendants_tracker (~> 0.0.4)
faraday (~> 0.8, < 0.10)
hashie (>= 3.2)
multi_json (>= 1.7.5, < 2.0)
nokogiri (~> 1.6.3)
oauth2
guard (2.6.1)
formatador (>= 0.2.4)
listen (~> 2.7)
lumberjack (~> 1.0)
pry (>= 0.9.12)
thor (>= 0.18.1)
guard-bundler (2.0.0)
bundler (~> 1.0)
guard (~> 2.2)
guard-rspec (4.3.1)
guard (~> 2.1)
rspec (>= 2.14, < 4.0)
hashie (3.3.1)
highline (1.6.21)
httparty (0.13.2)
json (~> 1.8)
multi_xml (>= 0.5.2)
jeweler (2.0.1)
builder
bundler (>= 1.0)
git (>= 1.2.5)
github_api
highline (>= 1.6.15)
nokogiri (>= 1.5.10)
rake
rdoc
json (1.8.1)
jwt (1.0.0)
listen (2.7.8)
celluloid (>= 0.15.2)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
lumberjack (1.0.6)
method_source (0.8.2)
mini_portile (0.6.0)
multi_json (1.10.1)
multi_xml (0.5.5)
multipart-post (2.0.0)
nokogiri (1.6.3.1)
mini_portile (= 0.6.0)
oauth2 (1.0.0)
faraday (>= 0.8, < 0.10)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (~> 1.2)
pry (0.10.0)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rack (1.5.2)
rake (10.3.2)
rb-fsevent (0.9.4)
rb-inotify (0.9.5)
ffi (>= 0.5.0)
rdoc (4.0.0)
rspec (3.1.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-core (3.1.7)
rspec-support (~> 3.1.0)
rspec-expectations (3.1.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.1.0)
rspec-mocks (3.1.3)
rspec-support (~> 3.1.0)
rspec-support (3.1.2)
simplecov (0.9.0)
docile (~> 1.1.0)
multi_json
simplecov-html (~> 0.8.0)
simplecov-html (0.8.0)
slop (3.5.0)
terminal-notifier-guard (1.5.3)
thor (0.19.1)
thread_safe (0.3.4)
timers (1.1.0)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.0)
fakeweb
guard-bundler
guard-rspec (~> 4.3.1)
httparty (>= 0.6.1)
jeweler (~> 2.0.1)
rspec
simplecov
terminal-notifier-guard
47 changes: 35 additions & 12 deletions README.md
Expand Up @@ -23,6 +23,11 @@ Currently Implmented
* Litmus::TestVersion.create(test_id)
* Litmus::Result.list(test_id, test_version_id)
* Litmus::Result.show(test_id, test_version_id, result_id)
* Litmus::Result.retest(test_id, test_version_id, result_id)
* Litmus::Result.update(test_id, test_version_id, result_id, new_state)
* Litmus::Report.list
* Litmus::Report.create(new_name)
* Litmus::Report.show(id)

Install
-------
Expand All @@ -34,38 +39,45 @@ Example Usage

# Setup the authentication details
use_ssl = true # You must turn on SSL here if you have SSL enabled in Litmus
Litmus::Base.new("your_company_subdomain", "username", "password", use_ssl)
Litmus::Base.configure("your_company_subdomain", "username", "password", use_ssl)

# Lets create an email test
email_test = Litmus::EmailTest.create
send_test_to = email_test["test_set_versions"].first["url_or_guid"] #=> "f1b17db@emailtests.com"
send_test_to = email_test["test_set_versions"].first["url_or_guid"] #=> "f1b17db@emailtests.com"
test_id = email_test["id"] #=> 1716534
version = email_test["test_set_versions"].first["version"] #=> 1

# If we query our new version we can see Litmus have not had the email yet
Litmus::TestVersion.show(test_id, version)["received"] #=> false

# Lets send them the email
Pony.mail(:to => send_test_to, :from => 'mail@matthewfawcett.co.uk', :subject => 'hi', :body => 'Hello there, this is a test')

# Alternatively, we could have included the email when the test was created
alternative_test = Litmus::EmailTest.create({:subject => 'Hello', :body => '<b>Hello, <i>world</i></b>'})

# Now they have it
Litmus::TestVersion.show(test_id, version)["received"] #=> "true"

# Lets poll the results and look at the first client
Litmus::TestVersion.poll(test_id, version)["results"].first.inspect #=> {"id"=>33539350, "test_code"=>"hotmail", "state"=>"pending"}

# The hotmail test is still pending, lets wait for a while
sleep 10

# Lets poll the results again and see that its complete
Litmus::TestVersion.poll(test_id, version).first.inspect #=> {"id"=>33539350, "test_code"=>"hotmail", "state"=>"complete"}
# Now lets show the result for this test version

# Now let's show the result for this test version
image_url = Litmus::Result.show(test_id, version, 33539350)["result_images"].first["full_image"] #=> "s3.amazonaws.com/resultcaptures/2f21fc9c-08f6-4429-b53d-2e224189526b.fullpageon.png"


# And we can retest the results
Litmus::Result.retest(test_id, version, 33539350)
# poll again until you have results

# And update the the state to ticked
Litmust::Result.update(test_id, version, 33539350, :ticked)

# Let's rename this test to something more intuitive
Litmus::Test.rename(test_id, 'My email test')

Expand All @@ -76,3 +88,14 @@ Example Usage

# Looks good! Let's clean up...
Litmus::Test.destroy(test_id)

# Next, let's try a report of email views
report = Litmus::Report.create("Newsletter")
report_id = report["id"]
html_to_include_in_email = report["bug_html"] # bug as in listening device, I assume

# Get the report later after the send
report = Litmus::Report.show(report_id)

# View a list of last 1000 reports
reports = Litmus::Report.list
40 changes: 20 additions & 20 deletions Rakefile
Expand Up @@ -19,27 +19,27 @@ rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end

require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
end

RSpec::Core::RakeTask.new(:rcov) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
spec.rcov = true
end
# require 'rspec/core'
# require 'rspec/core/rake_task'
# RSpec::Core::RakeTask.new(:spec) do |spec|
# spec.pattern = 'spec/**/*_spec.rb'
# end
#
# RSpec::Core::RakeTask.new(:rcov) do |spec|
# spec.pattern = 'spec/**/*_spec.rb'
# spec.rcov = true
# end

task :spec => :check_dependencies

task :default => :spec

require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""

rdoc.rdoc_dir = 'rdoc'
rdoc.title = "litmus #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
#
# require 'rake/rdoctask'
# Rake::RDocTask.new do |rdoc|
# version = File.exist?('VERSION') ? File.read('VERSION') : ""
#
# rdoc.rdoc_dir = 'rdoc'
# rdoc.title = "litmus #{version}"
# rdoc.rdoc_files.include('README*')
# rdoc.rdoc_files.include('lib/**/*.rb')
# end
3 changes: 2 additions & 1 deletion lib/litmus.rb
Expand Up @@ -6,6 +6,7 @@
require "litmus/page_test"
require "litmus/test_version"
require "litmus/result"
require "litmus/report"

module Litmus
end
end
13 changes: 8 additions & 5 deletions lib/litmus/base.rb
@@ -1,13 +1,16 @@
module Litmus
class Base
include HTTParty

# debug_output $stderr

def initialize(company, username, password, ssl = false)
self.class.configure(company, username, password, ssl)
end

def self.configure(company, username, password, ssl = false)
protocol = ssl ? 'https' : 'http'
self.class.base_uri "#{protocol}://#{company}.litmus.com"
self.class.basic_auth(username, password)
self.base_uri "#{protocol}://#{company}.litmus.com"
self.basic_auth(username, password)
end
end
end
end
20 changes: 20 additions & 0 deletions lib/litmus/report.rb
@@ -0,0 +1,20 @@
module Litmus
class Report < Base
def self.list
get("/reports.xml")["reports"]
end

def self.show(report_id)
get("/reports/#{report_id}.xml")["report"]
end

def self.create(name)
builder = Builder::XmlMarkup.new
builder.instruct! :xml, :version=>"1.0"
builder.report do |report|
report.name name if name
end
post('/reports.xml', :body => builder.target!, :headers => {"Content-type" => "application/xml"})["report"]
end
end
end
15 changes: 14 additions & 1 deletion lib/litmus/result.rb
Expand Up @@ -7,5 +7,18 @@ def self.list(test_id, version_id)
def self.show(test_id, version_id, id)
get("/tests/#{test_id}/versions/#{version_id}/results/#{id}.xml")["result"]
end

def self.update(test_id, version_id, id, new_state)
builder = Builder::XmlMarkup.new
builder.instruct! :xml, :version=>"1.0"
builder.result do |result|
result.check_state new_state
end
put("/tests/#{test_id}/versions/#{version_id}/results/#{id}.xml")["result"]
end

def self.retest(test_id, version_id, id)
post("/tests/#{test_id}/versions/#{version_id}/results/#{id}/retest.xml")
end
end
end
end

0 comments on commit 840338f

Please sign in to comment.