linkbucks 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format doc
2
+ --color
@@ -0,0 +1,3 @@
1
+ --markup markdown
2
+ -
3
+ README.md
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "yard"
10
+ gem "bundler", "~> 1.0"
11
+ gem "jeweler", "~> 2.0.1"
12
+ gem "rspec"
13
+ gem "webmock"
14
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 pacop
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # Linkbucks
2
+
3
+ Unofficial API Wrapper for Linkbucks.com
4
+
5
+ ## Some examples
6
+
7
+ ```
8
+ linkbucks = Linkbucks::API.new USER, PASSWORD
9
+ linkbucks.create_link_single originalLink: 'http://www.google.es'
10
+ => {"linkId"=>82924, "link"=>"http://www.linkbucks.com/987d3"}
11
+ ```
12
+
13
+ You can specify adType or contentType
14
+
15
+ ```
16
+ linkbucks.create_link_single originalLink: 'http://www.google.es', adType: :intermission, contentType: :clean
17
+ ```
18
+
19
+ ## Contributing to linkbucks
20
+
21
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
22
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
23
+ * Fork the project.
24
+ * Start a feature/bugfix branch.
25
+ * Commit and push until you are happy with your contribution.
26
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
27
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
28
+
29
+
30
+ ## Copyright
31
+
32
+ Copyright (c) 2014 pacop. See LICENSE.txt for
33
+ further details.
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "linkbucks"
18
+ gem.email = "pacopa.93@gmail.com"
19
+ gem.homepage = "http://github.com/pacop/linkbucks"
20
+ gem.license = "MIT"
21
+ gem.summary = %Q{Unofficial API Wrapper for Linkbucks.com}
22
+ gem.description = %Q{Unofficial API Wrapper for Linkbucks.com}
23
+ gem.email = "pacopa.93@gmail.com"
24
+ gem.authors = ["pacop"]
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec)
31
+
32
+ task :test => :spec
33
+
34
+ require 'yard'
35
+ YARD::Rake::YardocTask.new
36
+
37
+
38
+ task :default => [:spec]
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,2 @@
1
+ require 'linkbucks/error'
2
+ require 'linkbucks/linkbucks'
@@ -0,0 +1,5 @@
1
+ module Linkbucks
2
+ class AuthenticationFailed < StandardError; end
3
+ class ValidationFailed < StandardError; end
4
+ class OperationFailed < StandardError; end
5
+ end
@@ -0,0 +1,81 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'json'
4
+
5
+ module Linkbucks
6
+ # Unofficial API Wrapper for Linkbucks.com
7
+ class API
8
+
9
+ # Unique url API
10
+ URL_API = 'https://www.linkbucks.com/api/createLink/single'
11
+
12
+ # Valid content types
13
+ CONTENT_TYPE = {clean: 1, adult: 2}
14
+
15
+ # Valid ad types
16
+ AD_TYPE = {intermission: 2, locker: 4, shortLink: 5}
17
+
18
+ # Create instance to use API linkbucks
19
+ #
20
+ # If you want to get apiPassword see http://www.linkbucks.com/Profile
21
+ #
22
+ # @param user [String] Username
23
+ # @param pass [String] API password
24
+ def initialize user, pass
25
+ @user, @pass = user, pass
26
+ end
27
+
28
+ # Create single link
29
+ #
30
+ # Maybe you want to see http://www.linkbucks.com/CreateLinks/Tools
31
+ #
32
+ # @param data [Hash] data to send api
33
+ #
34
+ # @option data [String] :originalLink Link to be converted
35
+ # @option data [Symbol] :adType Type of advertisement {AD_TYPE See valid adTypes}
36
+ # @option data [Symbol] :contenType Type of page content {CONTENT_TYPE See valid contentType}
37
+ # @option data [String] :domain Alias domain to be used for ther generated link
38
+ #
39
+ # @example Simple use
40
+ # linkbucks.create_link_single(originalLink: 'http://www.google.es')['link']
41
+ #
42
+ # @return [Hash] Id and link
43
+ #
44
+ # @raise [AuthenticationFailed] user and apiPassword doesn't match
45
+ # @raise [ValidationFailed] when supplied data didn't pass validation.
46
+ # @raise [OperationFailed] Indicates processing error
47
+ # @raise [ArgumentError] Invalid parameters
48
+ # @raise [StandardError] Unknown error
49
+ def create_link_single data
50
+ data = {contentType: CONTENT_TYPE[:clean], adType: AD_TYPE[:intermission], domain: 'linkbucks.com'}.merge(data)
51
+
52
+ body = https_post URL_API, {user: @user, apiPassword: @pass}.merge(data)
53
+ body = JSON.parse body
54
+
55
+ return body unless body.include? 'errorCode'
56
+
57
+ case body['errorCode']
58
+ when 1
59
+ raise AuthenticationFailed, body['errorDescription']
60
+ when 2
61
+ raise ArgumentError, body['errorDescription']
62
+ when 3
63
+ raise ValidationFailed, body['errorDescription']
64
+ when 4
65
+ raise OperationFailed, body['errorDescription']
66
+ else
67
+ raise StandardError
68
+ end
69
+ end
70
+
71
+ private
72
+ def https_post url, data
73
+ uri = URI.parse(url)
74
+ https = Net::HTTP.new(uri.host, uri.port)
75
+ https.use_ssl = true
76
+ req = Net::HTTP::Post.new(uri.path)
77
+ req.body = data.to_json
78
+ https.request(req).body
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,65 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "linkbucks"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["pacop"]
12
+ s.date = "2014-02-09"
13
+ s.description = "Unofficial API Wrapper for Linkbucks.com"
14
+ s.email = "pacopa.93@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ ".yardopts",
23
+ "Gemfile",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/linkbucks.rb",
29
+ "lib/linkbucks/error.rb",
30
+ "lib/linkbucks/linkbucks.rb",
31
+ "linkbucks.gemspec",
32
+ "spec/linkbucks_spec.rb",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = "http://github.com/pacop/linkbucks"
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = "1.8.23"
39
+ s.summary = "Unofficial API Wrapper for Linkbucks.com"
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_development_dependency(%q<yard>, [">= 0"])
46
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
48
+ s.add_development_dependency(%q<rspec>, [">= 0"])
49
+ s.add_development_dependency(%q<webmock>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<yard>, [">= 0"])
52
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
53
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
54
+ s.add_dependency(%q<rspec>, [">= 0"])
55
+ s.add_dependency(%q<webmock>, [">= 0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<yard>, [">= 0"])
59
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
61
+ s.add_dependency(%q<rspec>, [">= 0"])
62
+ s.add_dependency(%q<webmock>, [">= 0"])
63
+ end
64
+ end
65
+
@@ -0,0 +1,48 @@
1
+ require 'linkbucks'
2
+ require_relative 'spec_helper'
3
+
4
+ describe Linkbucks::API do
5
+
6
+ let!(:linkbucks) { Linkbucks::API.new VALID_USER, VALID_PASS }
7
+
8
+ describe "#initialize" do
9
+ it "take two params" do
10
+ expect { Linkbucks::API.new('') }.to raise_error(ArgumentError)
11
+ expect { Linkbucks::API.new('', '') }.not_to raise_error
12
+ end
13
+ end
14
+
15
+ describe "#create_link_single" do
16
+ context 'with valid params' do
17
+ it "return hash" do
18
+ expect(linkbucks.create_link_single(originalLink: 'http://www.google.es')).to be_kind_of(Hash)
19
+ end
20
+
21
+ it "response has linkId and link" do
22
+ expect(linkbucks.create_link_single(originalLink: 'http://www.google.es')).to include('linkId' => VALID_LINK_ID, 'link' => VALID_LINK)
23
+ end
24
+ end
25
+
26
+ context 'with invalid params' do
27
+
28
+ it "return ArgumentError if adType is invalid" do
29
+ expect { linkbucks.create_link_single(originalLink: 'http://www.google.es', adType: 'invalid') }.to raise_error(ArgumentError)
30
+ end
31
+
32
+ it "return ValidationFailed if adType is invalid" do
33
+ expect { linkbucks.create_link_single(originalLink: 'google.es') }.to raise_error(Linkbucks::ValidationFailed)
34
+ end
35
+
36
+ it "return OperationFailed if adType is invalid" do
37
+ expect { linkbucks.create_link_single(originalLink: 'http://www.google.es', contentType:'operationFailed') }.to raise_error(Linkbucks::OperationFailed)
38
+ end
39
+
40
+ it "return AuthenticationFailed if user or pass are invalid" do
41
+ linkbucks = Linkbucks::API.new VALID_USER, INVALID_PASS
42
+ expect { linkbucks.create_link_single(originalLink: 'http://www.google.es') }.to raise_error(Linkbucks::AuthenticationFailed)
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,48 @@
1
+ require 'rspec'
2
+ require 'webmock'
3
+ require 'webmock/rspec'
4
+
5
+ VALID_USER = 'pacop'
6
+ VALID_PASS = '1234'
7
+ VALID_LINK_ID = 546
8
+ VALID_LINK = 'http://linkbucks.com/asd'
9
+
10
+ INVALID_PASS = 'invalid'
11
+
12
+
13
+ WebMock.disable_net_connect!(allow_localhost: true)
14
+
15
+ RSpec.configure do |config|
16
+ config.before(:each) do
17
+
18
+ stub_request(:post, "https://www.linkbucks.com/api/createLink/single").
19
+ with(:body => "{\"user\":\"#{VALID_USER}\",\"apiPassword\":\"#{VALID_PASS}\",\"contentType\":1,\"adType\":2,\"domain\":\"linkbucks.com\",\"originalLink\":\"http://www.google.es\"}",
20
+ :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
21
+ to_return(:status => 200, :body => "{\"linkId\": #{VALID_LINK_ID}, \"link\":\"#{VALID_LINK}\"}", :headers => {})
22
+
23
+ stub_request(:post, "https://www.linkbucks.com/api/createLink/single").
24
+ with(:body => "{\"user\":\"#{VALID_USER}\",\"apiPassword\":\"#{INVALID_PASS}\",\"contentType\":1,\"adType\":2,\"domain\":\"linkbucks.com\",\"originalLink\":\"http://www.google.es\"}",
25
+ :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
26
+ to_return(:status => 200, :body => '{"errorCode":1, "errorDescription":"Here message"}', :headers => {})
27
+
28
+ stub_request(:post, "https://www.linkbucks.com/api/createLink/single").
29
+ with(:body => "{\"user\":\"#{VALID_USER}\",\"apiPassword\":\"#{VALID_PASS}\",\"contentType\":1,\"adType\":\"invalid\",\"domain\":\"linkbucks.com\",\"originalLink\":\"http://www.google.es\"}",
30
+ :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
31
+ to_return(:status => 200, :body => '{"errorCode":2, "errorDescription":"Here message"}', :headers => {})
32
+
33
+ stub_request(:post, "https://www.linkbucks.com/api/createLink/single").
34
+ with(:body => "{\"user\":\"pacop\",\"apiPassword\":\"1234\",\"contentType\":1,\"adType\":2,\"domain\":\"linkbucks.com\",\"originalLink\":\"google.es\"}",
35
+ :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
36
+ to_return(:status => 200, :body =>'{"errorCode":3, "errorDescription":"Here message"}', :headers => {})
37
+
38
+ # Here we assume that API has operation failed with this (valid)input
39
+ stub_request(:post, "https://www.linkbucks.com/api/createLink/single").
40
+ with(:body => "{\"user\":\"pacop\",\"apiPassword\":\"1234\",\"contentType\":\"operationFailed\",\"adType\":2,\"domain\":\"linkbucks.com\",\"originalLink\":\"http://www.google.es\"}",
41
+ :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
42
+ to_return(:status => 200, :body =>'{"errorCode":4, "errorDescription":"Here message"}', :headers => {})
43
+
44
+
45
+ end
46
+ end
47
+
48
+
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: linkbucks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - pacop
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: yard
16
+ requirement: !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: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.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: '1.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: jeweler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.0.1
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: 2.0.1
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
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
+ - !ruby/object:Gem::Dependency
79
+ name: webmock
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Unofficial API Wrapper for Linkbucks.com
95
+ email: pacopa.93@gmail.com
96
+ executables: []
97
+ extensions: []
98
+ extra_rdoc_files:
99
+ - LICENSE.txt
100
+ - README.md
101
+ files:
102
+ - .document
103
+ - .rspec
104
+ - .yardopts
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - VERSION
110
+ - lib/linkbucks.rb
111
+ - lib/linkbucks/error.rb
112
+ - lib/linkbucks/linkbucks.rb
113
+ - linkbucks.gemspec
114
+ - spec/linkbucks_spec.rb
115
+ - spec/spec_helper.rb
116
+ homepage: http://github.com/pacop/linkbucks
117
+ licenses:
118
+ - MIT
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ segments:
130
+ - 0
131
+ hash: 924516465
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 1.8.23
141
+ signing_key:
142
+ specification_version: 3
143
+ summary: Unofficial API Wrapper for Linkbucks.com
144
+ test_files: []