adfly 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDg2ZWZmOWZlY2JmNDhhNzY0ZWUyNGNlYTRjMjM3YjdjYjNmOTM3Yg==
5
+ data.tar.gz: !binary |-
6
+ YzhhYmM4YmIwMmNhOWQ3OWE3MTY1NzkxYTJlY2Y0MzcyODY0Mjg3OA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NTFkNzNkODhhZDczMDY1ZTJiYTY1YjZhNjkxMjE0Njc2NTFjN2JmZmU2MWYx
10
+ NDZmZDg2MzBlMDE4YzMwMGQ0N2I4MmY5N2I1YjRkNTYwYTMwMzFjMjRiZGQ2
11
+ YmI4MWY0YjcyYjhmODNiMjZjZTkzZTU0M2U4NmI3NTYxYjFhZTg=
12
+ data.tar.gz: !binary |-
13
+ Y2MxN2M5OGQzOTU0MjZmYWI2Y2UzNWExYWQ4ZDdmMTJlOGZhNjVkZDQwM2Rj
14
+ NDIyMTNhNTkwMDJjYWYyYjA1NDYzYjVkZWZkZGE2ZWU1MjA0MTAzNjQ5NzYz
15
+ Y2E4OTY4ZGQ2MTBiNWVhZjI0MTk3YWRlNGFiMjJiOGI0MDM2Yjc=
@@ -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,50 @@
1
+ # Adfly
2
+
3
+ Unofficial API Wrapper for adf.ly
4
+
5
+ ## Installation
6
+
7
+ To use this rubygem:
8
+
9
+ ```
10
+ $ sudo gem install adfly
11
+ ```
12
+
13
+ With bundler:
14
+
15
+ ```
16
+ gem "adfly", "~> 0.0.1"
17
+ ```
18
+
19
+ ## Some examples
20
+
21
+ ```
22
+ adfly = Adfly::API.new UID, KEY
23
+ adfly.create_link url: 'http://www.google.es'
24
+ => "http://adf.ly/eY6Th"
25
+ ```
26
+
27
+ You can specify adver_type(:int or :banner) or domain
28
+
29
+ ```
30
+ adfly.create_link url: 'http://www.google.es', advert_type: :int, domain: 'q.gs'
31
+ => "http://q.gs/eY6Th"
32
+ ```
33
+
34
+ Maybe you want to read https://adf.ly/publisher/tools#tools-api
35
+
36
+ ## Contributing to adfly
37
+
38
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
39
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
40
+ * Fork the project.
41
+ * Start a feature/bugfix branch.
42
+ * Commit and push until you are happy with your contribution.
43
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
44
+ * 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.
45
+
46
+
47
+ ## Copyright
48
+
49
+ Copyright (c) 2014 pacop. See LICENSE.txt for
50
+ further details.
@@ -0,0 +1,37 @@
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.name = "adfly"
17
+ gem.email = "pacopa.93@gmail.com"
18
+ gem.homepage = "http://github.com/pacop/adfly"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Unofficial API Wrapper for adf.ly}
21
+ gem.description = %Q{Unofficial API Wrapper for adf.ly}
22
+ gem.email = "pacopa.93@gmail.com"
23
+ gem.authors = ["pacop"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core/rake_task'
29
+ RSpec::Core::RakeTask.new(:spec)
30
+
31
+ task :test => :spec
32
+
33
+ require 'yard'
34
+ YARD::Rake::YardocTask.new
35
+
36
+
37
+ task :default => [:spec]
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -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
+ # stub: adfly 0.0.1 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "adfly"
9
+ s.version = "0.0.1"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["pacop"]
14
+ s.date = "2014-03-06"
15
+ s.description = "Unofficial API Wrapper for adf.ly"
16
+ s.email = "pacopa.93@gmail.com"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".rspec",
24
+ ".yardopts",
25
+ "Gemfile",
26
+ "LICENSE.txt",
27
+ "README.md",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "adfly.gemspec",
31
+ "lib/adfly.rb",
32
+ "lib/adfly/adfly.rb",
33
+ "spec/adfly_spec.rb",
34
+ "spec/spec_helper.rb"
35
+ ]
36
+ s.homepage = "http://github.com/pacop/adfly"
37
+ s.licenses = ["MIT"]
38
+ s.rubygems_version = "2.2.2"
39
+ s.summary = "Unofficial API Wrapper for adf.ly"
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 4
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 @@
1
+ require 'adfly/adfly'
@@ -0,0 +1,53 @@
1
+ require 'net/http'
2
+
3
+
4
+ module Adfly
5
+ # Unofficial API Wrapper for adf.ly
6
+ class API
7
+
8
+ # Unique url API
9
+ URL_API = 'http://api.adf.ly/api.php'
10
+
11
+ # Create instance to use API adfly
12
+ #
13
+ # If you want to get API key from https://adf.ly/publisher/tools#tools-api
14
+ #
15
+ # @param uid [String] Uid
16
+ # @param key [String] Key
17
+ def initialize uid, key
18
+ @uid, @key = uid, key
19
+ end
20
+
21
+ # Create single link
22
+ #
23
+ # Maybe you want to see https://adf.ly/publisher/tools#tools-api
24
+ #
25
+ # @param data [Hash] data to send api
26
+ #
27
+ # @option data [String] :url Link to be converted
28
+ # @option data [Symbol] :advert_type Type of advertisement(:int or :banner)
29
+ # @option data [String] :domain Alias domain to be used for ther generated link
30
+ #
31
+ # @example Simple use
32
+ # adfly.create_link(url: 'http://www.google.es')
33
+ #
34
+ # @return [String] Short link
35
+ #
36
+ # @raise [ArgumentError] Invalid parameters, link cannot be created
37
+ def create_link data
38
+ body = http_get URL_API, {key: @key, uid: @uid}.merge(data)
39
+
40
+ raise ArgumentError if body.nil? || body.empty?
41
+ body
42
+ end
43
+
44
+ private
45
+ def http_get url, data
46
+ uri = URI(url)
47
+ uri.query = URI.encode_www_form(data)
48
+
49
+ res = Net::HTTP.get_response(uri)
50
+ res.body
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,37 @@
1
+ require 'adfly'
2
+ require_relative 'spec_helper'
3
+
4
+ describe Adfly::API do
5
+
6
+ let!(:adfly) { Adfly::API.new VALID_UID, VALID_KEY }
7
+
8
+ describe "#initialize" do
9
+ it "take two params" do
10
+ expect { Adfly::API.new('') }.to raise_error(ArgumentError)
11
+ expect { Adfly::API.new('', '') }.not_to raise_error
12
+ end
13
+ end
14
+
15
+ describe "#create_link" do
16
+ context 'with valid params' do
17
+ it "return string" do
18
+ expect(adfly.create_link(url: VALID_LINK)).to be_kind_of(String)
19
+ end
20
+
21
+ it "specifying advert_type or domain" do
22
+ expect(adfly.create_link(url: VALID_LINK, advert_type: :int, domain: 'q.gs')).to be_kind_of(String)
23
+ end
24
+
25
+ end
26
+
27
+ context 'with invalid params' do
28
+
29
+ it "return ArgumentError if url is invalid" do
30
+ expect { adfly.create_link(url: '') }.to raise_error(ArgumentError)
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,34 @@
1
+ require 'rspec'
2
+ require 'webmock'
3
+ require 'webmock/rspec'
4
+
5
+ VALID_UID = '1234'
6
+ VALID_KEY = 'valid_key'
7
+ VALID_LINK = 'http://google.es'
8
+
9
+ INVALID_PASS = 'invalid'
10
+
11
+
12
+ WebMock.disable_net_connect!(allow_localhost: true)
13
+
14
+ RSpec.configure do |config|
15
+ config.before(:each) do
16
+
17
+ stub_request(:get, "http://api.adf.ly/api.php?key=#{VALID_KEY}&uid=#{VALID_UID}&url=").
18
+ with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
19
+ to_return(:status => 200, :body => "", :headers => {})
20
+
21
+ stub_request(:get, "http://api.adf.ly/api.php?key=#{VALID_KEY}&uid=#{VALID_UID}&url=#{VALID_LINK}").
22
+ with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
23
+ to_return(:status => 200, :body => "http://adf.ly/eY6Th", :headers => {})
24
+
25
+
26
+ stub_request(:get, "http://api.adf.ly/api.php?advert_type=int&domain=q.gs&key=#{VALID_KEY}&uid=#{VALID_UID}&url=#{VALID_LINK}").
27
+ with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
28
+ to_return(:status => 200, :body => "http://q.gs/6kp3q", :headers => {})
29
+
30
+
31
+ end
32
+ end
33
+
34
+
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: adfly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - pacop
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yard
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jeweler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Unofficial API Wrapper for adf.ly
84
+ email: pacopa.93@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files:
88
+ - LICENSE.txt
89
+ - README.md
90
+ files:
91
+ - .document
92
+ - .rspec
93
+ - .yardopts
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - VERSION
99
+ - adfly.gemspec
100
+ - lib/adfly.rb
101
+ - lib/adfly/adfly.rb
102
+ - spec/adfly_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: http://github.com/pacop/adfly
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.2
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Unofficial API Wrapper for adf.ly
128
+ test_files: []