unbounce_client 0.0.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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ruby-1.9.3-p194@unbounce_client"
8
+
9
+ #
10
+ # Uncomment the following lines if you want to verify rvm version per project
11
+ #
12
+ # rvmrc_rvm_version="1.10.2" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+ #
18
+
19
+ #
20
+ # Uncomment following line if you want options to be set only for given project.
21
+ #
22
+ # PROJECT_JRUBY_OPTS=( --1.9 )
23
+ #
24
+ # The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
25
+ #
26
+ # chmod +x ${rvm_path}/hooks/after_use_jruby_opts
27
+ #
28
+
29
+ #
30
+ # First we attempt to load the desired environment directly from the environment
31
+ # file. This is very fast and efficient compared to running through the entire
32
+ # CLI and selector. If you want feedback on which environment was used then
33
+ # insert the word 'use' after --create as this triggers verbose mode.
34
+ #
35
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
36
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
37
+ then
38
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
39
+
40
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
41
+ then
42
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
43
+ fi
44
+ else
45
+ # If the environment file has not yet been created, use the RVM CLI to select.
46
+ if ! rvm --create "$environment_id"
47
+ then
48
+ echo "Failed to create RVM environment '${environment_id}'."
49
+ return 1
50
+ fi
51
+ fi
52
+
53
+ #
54
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
55
+ # it be automatically loaded. Uncomment the following and adjust the filename if
56
+ # necessary.
57
+ #
58
+ # filename=".gems"
59
+ # if [[ -s "$filename" ]]
60
+ # then
61
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
62
+ # fi
63
+
64
+ # If you use bundler, this might be useful to you:
65
+ # if [[ -s Gemfile ]] && ! command -v bundle >/dev/null
66
+ # then
67
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
68
+ # gem install bundler
69
+ # fi
70
+ # if [[ -s Gemfile ]] && command -v bundle
71
+ # then
72
+ # bundle install
73
+ # fi
74
+
75
+ if [[ $- == *i* ]] # check for interactive shells
76
+ then
77
+ echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
78
+ else
79
+ echo "Using: $GEM_HOME" # don't use colors in interactive shells
80
+ fi
81
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Aaron Oman
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,87 @@
1
+ # UnbounceClient
2
+
3
+ This is a Ruby wrapper around the [Unbounce API](https://api.unbounce.com).
4
+
5
+ ##Installation
6
+ Add this line to your project's Gemfile:
7
+
8
+ ```
9
+ gem 'unbounce_client'
10
+ ```
11
+
12
+ Then execute:
13
+
14
+ ```
15
+ bundle install
16
+ ```
17
+
18
+ Or, install it yourself with:
19
+
20
+ ```
21
+ $ gem install unbounce_client
22
+ ```
23
+
24
+ ##Usage
25
+
26
+ **First, make sure you have an Unbounce API Key.** See the [Unbounce API Reference Documentation](https://api.unbounce.com/doc) for information on how.
27
+
28
+ Create a new instance:
29
+
30
+ ```Ruby
31
+ ub = UnbounceClient.new(MY_API_KEY)
32
+ ```
33
+
34
+ Get your Accounts list:
35
+
36
+ ```Ruby
37
+ accounts = ub.accounts
38
+ ```
39
+
40
+ Get your Sub Accounts:
41
+
42
+ ```Ruby
43
+ # Get a list of Sub Accounts:
44
+ sub_accounts = ub.sub_accounts(accounts.first.id)
45
+
46
+ # Get a specific Sub Account:
47
+ sub_account = ub.sub_account(sub_accounts.first.id)
48
+ ```
49
+
50
+ Get your Page Groups:
51
+
52
+ ```Ruby
53
+ page_groups = ub.page_groups(sub_account.id)
54
+ ```
55
+
56
+ Get your Domains:
57
+
58
+ ```Ruby
59
+ domains = ub.domains(sub_account.id)
60
+ ```
61
+
62
+ Get your Pages:
63
+
64
+ ```Ruby
65
+ # Get a list of Pages:
66
+ pages = ub.pages(sub_account_id: sub_account.id)
67
+
68
+ # Get a specific Page:
69
+ page = ub.page(pages.first.id)
70
+ ```
71
+
72
+ Get your Leads:
73
+
74
+ ```Ruby
75
+ # Get a list of Leads:
76
+ leads = ub.leads(page_id: page.id)
77
+
78
+ # Get a specific Lead:
79
+ lead = ub.lead(leads.first.id)
80
+ ```
81
+
82
+ ##Contributing
83
+ 1. Fork it
84
+ 2. Create your feature branch (git checkout -b my-new-feature)
85
+ 3. Commit your changes (git commit -am 'Add some feature')
86
+ 4. Push to the branch (git push origin my-new-feature)
87
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require "bundler/gem_tasks"
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'lib/unbounce_client'
8
+ t.test_files = FileList['test/lib/unbounce_client/*_test.rb']
9
+ t.verbose = true
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,3 @@
1
+ module UnbounceClientUtils
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,80 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ class UnbounceClient
5
+ include HTTParty
6
+ base_uri 'https://api.unbounce.com'
7
+ headers('Accept' => 'application/vnd.unbounce.api.v0.1+json')
8
+
9
+ @format
10
+
11
+ def initialize(api_key)
12
+ @auth = { username: api_key, password: '' }
13
+ end
14
+
15
+ def root
16
+ parse get('/')
17
+ end
18
+
19
+ def accounts
20
+ parse( get('/accounts') )['accounts'].collect { |account| OpenStruct.new(account) }
21
+ end
22
+
23
+ def sub_accounts(account_id)
24
+ parse( get("/accounts/#{account_id}/sub_accounts") )['subAccounts'].collect { |sub_account| OpenStruct.new(sub_account) }
25
+ end
26
+
27
+ def sub_account(id)
28
+ OpenStruct.new( parse( get("/sub_accounts/#{id}") ) )
29
+ end
30
+
31
+ def domains(id)
32
+ parse( get("/sub_accounts/#{id}/domains") )['domains'].collect { |domain| OpenStruct.new(domain) }
33
+ end
34
+
35
+ def page_groups(sub_account_id)
36
+ parse( get("/sub_accounts/#{sub_account_id}/page_groups") )['pageGroups'].collect { |page_group| OpenStruct.new(page_group) }
37
+ end
38
+
39
+ def pages(opts={ account_id: nil, sub_account_id: nil, page_group_id: nil })
40
+ parent, id = opts_to_path_and_id(opts)
41
+
42
+ parse( get("/#{parent}/#{id}/pages") )['pages'].collect { |page| OpenStruct.new(page) }
43
+ end
44
+
45
+ def page(id)
46
+ OpenStruct.new( parse( get("/pages/#{id}") ) )
47
+ end
48
+
49
+ def leads(opts={ sub_account_id: nil, page_id: nil })
50
+ parent, id = opts_to_path_and_id(opts)
51
+
52
+ parse( get("/#{parent}/#{id}/leads") )['leads'].collect { |lead| OpenStruct.new(lead) }
53
+ end
54
+
55
+ def lead(id)
56
+ OpenStruct.new( parse( get("/leads/#{id}") ) )
57
+ end
58
+
59
+ private
60
+
61
+ def opts_to_path_and_id(opts)
62
+ # Trim out all empty keys.
63
+ opts = opts.keep_if { |k,v| !v.nil? }
64
+ # Now grab the first key/value pair only.
65
+ parent, id = [opts.keys.first, opts[opts.keys.first]]
66
+ # Remove the trailing '_id' from the parent identifier.
67
+ parent = parent.to_s.gsub(/_id/, '')
68
+
69
+ ["#{parent}s", id]
70
+ end
71
+
72
+ def get(url)
73
+ self.class.get(url, basic_auth: @auth)
74
+ end
75
+
76
+ def parse(response)
77
+ JSON.parse(response.parsed_response)
78
+ end
79
+
80
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe UnbounceClient do
4
+
5
+ it 'works'
6
+
7
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path('../../lib/unbounce_client', __FILE__)
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'unbounce_client/version'
6
+
7
+ Gem::Specification.new do |gem|
8
+ gem.name = 'unbounce_client'
9
+ gem.version = UnbounceClientUtils::VERSION
10
+ gem.authors = ['Aaron Oman']
11
+ gem.email = ['aaron@unbounce.com']
12
+ gem.description = %q{Convenient recursive methods to extend Ruby's built-in Hash.}
13
+ gem.summary = %q{Destructive and non-destructive recursive methods to augment the build in Hash.}
14
+ gem.homepage = ''
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ['lib']
20
+
21
+ gem.add_development_dependency 'rake'
22
+ gem.add_development_dependency 'rspec'
23
+
24
+ gem.add_dependency 'httparty'
25
+ gem.add_dependency 'json'
26
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unbounce_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aaron Oman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70216618242400 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70216618242400
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70216618241880 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70216618241880
36
+ - !ruby/object:Gem::Dependency
37
+ name: httparty
38
+ requirement: &70216618241400 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70216618241400
47
+ - !ruby/object:Gem::Dependency
48
+ name: json
49
+ requirement: &70216618240960 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70216618240960
58
+ description: Convenient recursive methods to extend Ruby's built-in Hash.
59
+ email:
60
+ - aaron@unbounce.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - .rvmrc
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - lib/unbounce_client.rb
72
+ - lib/unbounce_client/version.rb
73
+ - spec/lib/unbounce_client_spec.rb
74
+ - spec/spec_helper.rb
75
+ - unbounce_client.gemspec
76
+ homepage: ''
77
+ licenses: []
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ segments:
89
+ - 0
90
+ hash: 3201399805524397646
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ segments:
98
+ - 0
99
+ hash: 3201399805524397646
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 1.8.15
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Destructive and non-destructive recursive methods to augment the build in
106
+ Hash.
107
+ test_files:
108
+ - spec/lib/unbounce_client_spec.rb
109
+ - spec/spec_helper.rb