launchrock 1.0.0
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/Gemfile +9 -0
- data/README.md +17 -0
- data/Rakefile +20 -0
- data/lib/launchrock.rb +13 -0
- data/lib/launchrock/connection.rb +18 -0
- data/lib/launchrock/models/client.rb +29 -0
- data/lib/launchrock/models/site.rb +53 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 36947ec879ac80e9f4a1ed4fadba46527cd5d9b4
|
4
|
+
data.tar.gz: d4152077e8a0fc0d911815950c2875dc23a98d92
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 93d65deca3825605cf00cd22491cb89136df8bec8e8f7612aeaef531a76863d74c570a570ca2acbd05e9cd2be56731b79fe38334f0940d3ef4ee142e826a263b
|
7
|
+
data.tar.gz: fd0695227e598e6904a65c8ebd065232c84bae85753a411c1e964fd44afdc523701f6d55ab1dd017896d68f6793755884ea3b1e2d6e5a123f74452f4676a982d
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Launchrock - Ruby Gem
|
2
|
+
------------
|
3
|
+
|
4
|
+
This gem integrates with the launchrock API's documented [here](http://developers.launchrock.com/documentation/welcome). The API isn't well documented, and this also includes integration with undocumented API's. This means parts of this gem could break with no notice whatsoever. Use at your own risk.
|
5
|
+
|
6
|
+
Usage
|
7
|
+
-----
|
8
|
+
|
9
|
+
```
|
10
|
+
# First authenticate and fetch the user session
|
11
|
+
|
12
|
+
client = Launchrock::Client.find_by_email_and_password('testman@yoloswag.com', 'testpassword-oooo')
|
13
|
+
site = client.site_named(args[:site_name])
|
14
|
+
raise "No site info found" unless site
|
15
|
+
|
16
|
+
puts site.users.map(&:to_hash).inspect
|
17
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
require 'rake'
|
12
|
+
|
13
|
+
require 'rake/testtask'
|
14
|
+
Rake::TestTask.new(:test) do |test|
|
15
|
+
test.test_files = FileList['test/**/*_test.rb']
|
16
|
+
test.libs = ['lib', 'test']
|
17
|
+
end
|
18
|
+
|
19
|
+
task :default => :test
|
20
|
+
|
data/lib/launchrock.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'active_support/all'
|
5
|
+
require 'httparty'
|
6
|
+
require 'csv'
|
7
|
+
|
8
|
+
Dir[File.dirname(__FILE__) + '/launchrock/*.rb'].each {|m| require m}
|
9
|
+
Dir[File.dirname(__FILE__) + '/launchrock/models/*.rb'].each {|m| require m}
|
10
|
+
|
11
|
+
CSV::HeaderConverters[:launchrock] = lambda do |s|
|
12
|
+
s.to_s.gsub("lr_", '').to_sym
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Launchrock
|
2
|
+
class Connection
|
3
|
+
include HTTParty
|
4
|
+
base_uri "http://platform.launchrock.com"
|
5
|
+
|
6
|
+
def self.perform_post(uri, body)
|
7
|
+
resp = HTTParty.post("#{base_uri}#{uri}", { :body => body }).first['response']
|
8
|
+
|
9
|
+
unless resp['status'] == 'OK'
|
10
|
+
raise ApiError, "API Call Failed"
|
11
|
+
end
|
12
|
+
resp
|
13
|
+
end
|
14
|
+
|
15
|
+
class ApiError < StandardError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Launchrock
|
2
|
+
class Client < Launchrock::Connection
|
3
|
+
attr_accessor :client_id, :session_id
|
4
|
+
|
5
|
+
def initialize(client_id, session_id)
|
6
|
+
self.client_id, self.session_id = client_id, session_id
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.find_by_email_and_password(email, password)
|
10
|
+
begin
|
11
|
+
attributes = perform_post('/v1/platformUserLogin', { :email => email, :password => password })['platform_user'].to_hash.symbolize_keys.slice(:session_id, :UID)
|
12
|
+
rescue
|
13
|
+
return nil
|
14
|
+
end
|
15
|
+
|
16
|
+
Client.new(attributes[:UID], attributes[:session_id])
|
17
|
+
end
|
18
|
+
|
19
|
+
# WARNING: undocumented API
|
20
|
+
def sites
|
21
|
+
Launchrock::Site.all(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
# WARNING: undocumented API
|
25
|
+
def site_named(name)
|
26
|
+
Launchrock::Site.by_name(self, name)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Launchrock
|
2
|
+
class Site < Launchrock::Connection
|
3
|
+
attr_accessor :id, :name, :client, :access_token
|
4
|
+
|
5
|
+
def initialize(client, id, name)
|
6
|
+
self.client, self.id, self.name = client, id, name
|
7
|
+
end
|
8
|
+
|
9
|
+
# WARNING: undocumented API
|
10
|
+
def self.all(client)
|
11
|
+
attributes = perform_post("/v1/getPlatformUserSites", {:user_id => client.client_id })['platform_user_sites']
|
12
|
+
|
13
|
+
attributes.map(&:symbolize_keys).map do |attrs|
|
14
|
+
Site.new(client, attrs[:SID], attrs[:siteName])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# WARNING: undocumented API
|
19
|
+
def self.by_name(client, name)
|
20
|
+
all(client).find do |site|
|
21
|
+
site.name == name
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def access_token
|
26
|
+
@access_token ||= self.class.perform_post('/v1/getSiteApiToken',{
|
27
|
+
:user_id => self.client.client_id,
|
28
|
+
:session_id => self.client.session_id,
|
29
|
+
:site_id => self.id
|
30
|
+
})['api_info']['access_token']
|
31
|
+
end
|
32
|
+
|
33
|
+
# WARNING: undocumented API
|
34
|
+
def users
|
35
|
+
resp = HTTParty.get(users_url)
|
36
|
+
raise Launchrock::Connection::ApiError, "An error occurred while fetching the list" unless resp.success?
|
37
|
+
|
38
|
+
CSV.parse(resp.body, :headers => true, :header_converters => :launchrock)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def users_url
|
44
|
+
params = {
|
45
|
+
:user_id => self.client.client_id,
|
46
|
+
:access_token => self.access_token,
|
47
|
+
:site_id => self.id
|
48
|
+
}
|
49
|
+
|
50
|
+
url = [ self.class.base_uri, "/export", "?", params.to_query].join
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: launchrock
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ken mazaika
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.10
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.10
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
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
|
+
description: A ruby gem to integrate with the launchrock API
|
42
|
+
email: kenmazaika@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files:
|
46
|
+
- README.md
|
47
|
+
files:
|
48
|
+
- Gemfile
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- lib/launchrock.rb
|
52
|
+
- lib/launchrock/connection.rb
|
53
|
+
- lib/launchrock/models/client.rb
|
54
|
+
- lib/launchrock/models/site.rb
|
55
|
+
homepage: https://github.com/kenmazaika/launchrock
|
56
|
+
licenses:
|
57
|
+
- Yoloswag
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.0.0
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: A ruby gem to integrate with the launchrock API, with support for undocumented
|
79
|
+
APIs
|
80
|
+
test_files: []
|