pixy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +24 -0
- data/README.md +34 -0
- data/Rakefile +2 -0
- data/lib/pixy.rb +13 -0
- data/lib/pixy/shorten.rb +21 -0
- data/lib/pixy/version.rb +3 -0
- data/pixy.gemspec +19 -0
- metadata +65 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Copyright (c) 2011 Nihad Abbasov / NARKOZ
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
12
|
+
and/or other materials provided with the distribution.
|
13
|
+
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
15
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
16
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
17
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
18
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
19
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
20
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
21
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
22
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
23
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
24
|
+
POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Pixy
|
2
|
+
|
3
|
+
Pixy is an API wrapper for Pixiv url shortener - [p.tl](http://p.tl/)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'pixy'
|
9
|
+
# gem install pixy
|
10
|
+
```
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
url = Pixy.shorten!(API_KEY, 'https://github.com/narkoz/pixy')
|
16
|
+
# => #<Pixy::Shorten:0x0000010201bde8 @status="ok", @long_url="https://github.com/narkoz/pixy", @short_url="http://p.tl/Us9R", @counter=20>
|
17
|
+
|
18
|
+
url.status
|
19
|
+
# => "ok"
|
20
|
+
|
21
|
+
url.long_url
|
22
|
+
# => "https://github.com/narkoz/pixy"
|
23
|
+
|
24
|
+
url.short_url
|
25
|
+
# => "http://p.tl/Us9R"
|
26
|
+
|
27
|
+
url.counter
|
28
|
+
# => 20
|
29
|
+
```
|
30
|
+
|
31
|
+
## Copyright
|
32
|
+
|
33
|
+
Copyright (c) 2011 Nihad Abbasov
|
34
|
+
BSD License.
|
data/Rakefile
ADDED
data/lib/pixy.rb
ADDED
data/lib/pixy/shorten.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Pixy
|
2
|
+
class Shorten
|
3
|
+
attr_accessor :status, :long_url, :short_url, :counter
|
4
|
+
|
5
|
+
def initialize(key, url)
|
6
|
+
uri = URI('http://p.tl/api/api_simple.php')
|
7
|
+
uri.query = URI.encode_www_form({:key => key, :url => url})
|
8
|
+
response = Net::HTTP.get_response(uri)
|
9
|
+
result = JSON.parse(response.body)
|
10
|
+
|
11
|
+
if response.code.to_i == 200
|
12
|
+
self.status = result['status']
|
13
|
+
self.long_url = result['long_url']
|
14
|
+
self.short_url = result['short_url']
|
15
|
+
self.counter = result['counter']
|
16
|
+
else
|
17
|
+
raise "Server responded with code #{response.code}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/pixy/version.rb
ADDED
data/pixy.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/pixy/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Nihad Abbasov"]
|
6
|
+
gem.email = ["mail@narkoz.me"]
|
7
|
+
gem.description = %q{Pixy is an API wrapper for Pixiv url shortener - p.tl}
|
8
|
+
gem.summary = %q{API wrapper for Pixiv url shortener}
|
9
|
+
gem.homepage = "https://github.com/narkoz/pixy"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "pixy"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Pixy::VERSION
|
17
|
+
|
18
|
+
gem.add_runtime_dependency 'json'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pixy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nihad Abbasov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: &2151918060 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2151918060
|
25
|
+
description: Pixy is an API wrapper for Pixiv url shortener - p.tl
|
26
|
+
email:
|
27
|
+
- mail@narkoz.me
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- LICENSE.txt
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- lib/pixy.rb
|
38
|
+
- lib/pixy/shorten.rb
|
39
|
+
- lib/pixy/version.rb
|
40
|
+
- pixy.gemspec
|
41
|
+
homepage: https://github.com/narkoz/pixy
|
42
|
+
licenses: []
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.8.12
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: API wrapper for Pixiv url shortener
|
65
|
+
test_files: []
|