pixy 0.1.1 → 0.1.2
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/.travis.yml +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +2 -2
- data/lib/pixy/errors.rb +8 -7
- data/lib/pixy/shorten.rb +2 -2
- data/lib/pixy/version.rb +1 -1
- data/lib/pixy.rb +8 -13
- data/pixy.gemspec +1 -1
- data/spec/pixy/shorten_spec.rb +42 -59
- data/spec/pixy_spec.rb +28 -0
- metadata +39 -33
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2b605a212e121ae3c92c780497fe7d9cfc37614b
|
4
|
+
data.tar.gz: 2dbd56e9d55bc15a1c3b9a9e444ed26cdd2d274d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 49a5366f356011b36dfedb1c807115e880df36f25136b3ddb3075b8feeba75a1a685ea82d6209e16e5f4185a2baccf696a35b6c7ae9b87708e97b0c5f988049f
|
7
|
+
data.tar.gz: 124ddc6aa5de4025bb760425c3053fc04d6288b256a75f55e6c44affdd91cab4154efe51428b7290d553a702e717fe50bf07f5ed88925473feef79520cf56bda
|
data/.travis.yml
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Pixy [](http://travis-ci.org/NARKOZ/pixy)
|
2
2
|
|
3
3
|
Pixy is an API wrapper for Pixiv url shortener - [p.tl](http://p.tl/)
|
4
4
|
|
@@ -37,5 +37,5 @@ pixy.counter
|
|
37
37
|
|
38
38
|
## Copyright
|
39
39
|
|
40
|
-
Copyright (c) 2011 Nihad Abbasov
|
40
|
+
Copyright (c) 2011-2013 Nihad Abbasov
|
41
41
|
BSD License.
|
data/lib/pixy/errors.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
module Pixy
|
2
|
-
class
|
3
|
-
class
|
4
|
-
class
|
5
|
-
class
|
6
|
-
class
|
7
|
-
class
|
8
|
-
class
|
2
|
+
class Error < StandardError; end
|
3
|
+
class EmptyLongUrl < Error; end
|
4
|
+
class EmptyApiKey < Error; end
|
5
|
+
class ApiLimit < Error; end
|
6
|
+
class InvalidApiKey < Error; end
|
7
|
+
class InvalidLongUrl < Error; end
|
8
|
+
class UnknownError < Error; end
|
9
|
+
class MissingApiKey < Error; end
|
9
10
|
end
|
data/lib/pixy/shorten.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Pixy
|
2
2
|
class Shorten
|
3
3
|
API_URL = 'http://p.tl/api/api_simple.php'
|
4
|
-
|
4
|
+
attr_reader :status, :long_url, :short_url, :counter
|
5
5
|
|
6
6
|
def initialize(key, url)
|
7
7
|
uri = URI "#{API_URL}?key=#{key}&url=#{escape_url escape_url(url)}"
|
8
8
|
response = Net::HTTP.get_response(uri)
|
9
|
-
result =
|
9
|
+
result = MultiJson.load(response.body)
|
10
10
|
|
11
11
|
if response.code.to_i == 200
|
12
12
|
@status = result['status']
|
data/lib/pixy/version.rb
CHANGED
data/lib/pixy.rb
CHANGED
@@ -2,25 +2,20 @@ require 'pixy/version'
|
|
2
2
|
require 'pixy/shorten'
|
3
3
|
require 'pixy/errors'
|
4
4
|
require 'net/http'
|
5
|
-
require '
|
5
|
+
require 'multi_json'
|
6
6
|
|
7
7
|
module Pixy
|
8
|
-
|
9
|
-
|
10
|
-
def shorten(key=nil, url='')
|
8
|
+
def self.shorten(key=nil, url='')
|
11
9
|
raise MissingApiKey, "API key is required" if key.nil?
|
12
|
-
|
10
|
+
Shorten.new(key, url)
|
13
11
|
end
|
14
12
|
|
15
|
-
def shorten!(key=nil, url='')
|
16
|
-
|
13
|
+
def self.shorten!(key=nil, url='')
|
14
|
+
shorten(key, url).short_url
|
17
15
|
end
|
18
16
|
|
19
|
-
def stats(key=nil, url='^')
|
20
|
-
pixy =
|
21
|
-
{
|
22
|
-
:calls => pixy.counter,
|
23
|
-
:limit => 1000 - pixy.counter
|
24
|
-
}
|
17
|
+
def self.stats(key=nil, url='^')
|
18
|
+
pixy = shorten(key, url) # submit fake url to get API rate limit
|
19
|
+
{ :calls => pixy.counter, :limit => 1000 - pixy.counter }
|
25
20
|
end
|
26
21
|
end
|
data/pixy.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = Pixy::VERSION
|
17
17
|
|
18
|
-
gem.
|
18
|
+
gem.add_dependency 'multi_json', '~> 1.7'
|
19
19
|
|
20
20
|
gem.add_development_dependency 'rake'
|
21
21
|
gem.add_development_dependency 'rspec'
|
data/spec/pixy/shorten_spec.rb
CHANGED
@@ -1,79 +1,62 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Pixy::Shorten do
|
4
|
-
|
5
|
-
it { Pixy.should respond_to :shorten! }
|
4
|
+
let(:pixy) { Pixy::Shorten.new('API_KEY', 'https://github.com/narkoz/pixy') }
|
6
5
|
|
7
|
-
describe "#
|
8
|
-
it "should return a
|
9
|
-
|
6
|
+
describe "#status" do
|
7
|
+
it "should return a response status" do
|
8
|
+
pixy.status.should == 'ok'
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
lambda { Pixy.shorten }.should raise_error(Pixy::MissingApiKey, "API key is required")
|
17
|
-
end
|
12
|
+
describe "#long_url" do
|
13
|
+
it "should return a long url" do
|
14
|
+
pixy.long_url.should == 'https://github.com/narkoz/pixy'
|
18
15
|
end
|
16
|
+
end
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
subject.status.should == 'ok'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#long_url" do
|
30
|
-
it "should return a long url" do
|
31
|
-
subject.long_url.should == 'https://github.com/narkoz/pixy'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "#short_url" do
|
36
|
-
it "should return a short url" do
|
37
|
-
subject.short_url.should == 'http://p.tl/Us9R'
|
38
|
-
end
|
39
|
-
end
|
18
|
+
describe "#short_url" do
|
19
|
+
it "should return a short url" do
|
20
|
+
pixy.short_url.should == 'http://p.tl/Us9R'
|
21
|
+
end
|
22
|
+
end
|
40
23
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
24
|
+
describe "#counter" do
|
25
|
+
it "should return a request number" do
|
26
|
+
pixy.counter.should == 12
|
27
|
+
end
|
28
|
+
end
|
46
29
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
30
|
+
describe "exceptions" do
|
31
|
+
context "when empty long url" do
|
32
|
+
it "should raise EmptyLongUrl" do
|
33
|
+
expect {
|
34
|
+
Pixy::Shorten.new('API_KEY', '')
|
35
|
+
}.to raise_error(Pixy::EmptyLongUrl, "Missing long URL.")
|
53
36
|
end
|
37
|
+
end
|
54
38
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
39
|
+
context "when empty API key" do
|
40
|
+
it "should raise EmptyApiKey" do
|
41
|
+
expect {
|
42
|
+
Pixy::Shorten.new('', 'https://github.com/narkoz/pixy')
|
43
|
+
}.to raise_error(Pixy::EmptyApiKey, "Missing API key.")
|
61
44
|
end
|
45
|
+
end
|
62
46
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
47
|
+
context "when invalid API key" do
|
48
|
+
it "should raise InvalidApiKey" do
|
49
|
+
expect {
|
50
|
+
Pixy::Shorten.new('invalid_API_KEY', 'https://github.com/narkoz/pixy')
|
51
|
+
}.to raise_error(Pixy::InvalidApiKey, "API key is invalid.")
|
69
52
|
end
|
53
|
+
end
|
70
54
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
55
|
+
context "when invalid long url" do
|
56
|
+
it "should raise InvalidLongUrl" do
|
57
|
+
expect {
|
58
|
+
Pixy::Shorten.new('API_KEY', '^_^')
|
59
|
+
}.to raise_error(Pixy::InvalidLongUrl, "The URL can not be shortened.")
|
77
60
|
end
|
78
61
|
end
|
79
62
|
end
|
data/spec/pixy_spec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pixy do
|
4
|
+
it { should respond_to :shorten }
|
5
|
+
it { should respond_to :shorten! }
|
6
|
+
it { should respond_to :stats }
|
7
|
+
|
8
|
+
describe "#shorten" do
|
9
|
+
context "without arguments" do
|
10
|
+
it "should raise a required API key error" do
|
11
|
+
expect { Pixy.shorten }.to raise_error(Pixy::MissingApiKey, "API key is required")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with arguments" do
|
16
|
+
it "should return an instance of Pixy::Shorten" do
|
17
|
+
pixy = Pixy.shorten('API_KEY', 'https://github.com/narkoz/pixy')
|
18
|
+
pixy.should be_a_kind_of Pixy::Shorten
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#shorten!" do
|
24
|
+
it "should return a short url" do
|
25
|
+
Pixy.shorten!('API_KEY', 'https://github.com/narkoz/pixy').should == 'http://p.tl/Us9R'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,60 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pixy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nihad Abbasov
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-04-06 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement:
|
17
|
-
none: false
|
14
|
+
name: multi_json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
19
|
+
version: '1.7'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: rake
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - '>='
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: rspec
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- -
|
45
|
+
- - '>='
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: '0'
|
44
48
|
type: :development
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
56
|
name: fakeweb
|
49
|
-
requirement:
|
50
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
51
58
|
requirements:
|
52
|
-
- -
|
59
|
+
- - '>='
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '0'
|
55
62
|
type: :development
|
56
63
|
prerelease: false
|
57
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
58
69
|
description: Pixy is an API wrapper for Pixiv url shortener - p.tl
|
59
70
|
email:
|
60
71
|
- mail@narkoz.me
|
@@ -79,36 +90,30 @@ files:
|
|
79
90
|
- spec/fixtures/invalid_long_url.json
|
80
91
|
- spec/fixtures/ok.json
|
81
92
|
- spec/pixy/shorten_spec.rb
|
93
|
+
- spec/pixy_spec.rb
|
82
94
|
- spec/spec_helper.rb
|
83
95
|
homepage: https://github.com/narkoz/pixy
|
84
96
|
licenses: []
|
97
|
+
metadata: {}
|
85
98
|
post_install_message:
|
86
99
|
rdoc_options: []
|
87
100
|
require_paths:
|
88
101
|
- lib
|
89
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
103
|
requirements:
|
92
|
-
- -
|
104
|
+
- - '>='
|
93
105
|
- !ruby/object:Gem::Version
|
94
106
|
version: '0'
|
95
|
-
segments:
|
96
|
-
- 0
|
97
|
-
hash: 1002057726999351752
|
98
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
-
none: false
|
100
108
|
requirements:
|
101
|
-
- -
|
109
|
+
- - '>='
|
102
110
|
- !ruby/object:Gem::Version
|
103
111
|
version: '0'
|
104
|
-
segments:
|
105
|
-
- 0
|
106
|
-
hash: 1002057726999351752
|
107
112
|
requirements: []
|
108
113
|
rubyforge_project:
|
109
|
-
rubygems_version:
|
114
|
+
rubygems_version: 2.0.3
|
110
115
|
signing_key:
|
111
|
-
specification_version:
|
116
|
+
specification_version: 4
|
112
117
|
summary: API wrapper for Pixiv url shortener
|
113
118
|
test_files:
|
114
119
|
- spec/fixtures/empty_api_key.json
|
@@ -117,4 +122,5 @@ test_files:
|
|
117
122
|
- spec/fixtures/invalid_long_url.json
|
118
123
|
- spec/fixtures/ok.json
|
119
124
|
- spec/pixy/shorten_spec.rb
|
125
|
+
- spec/pixy_spec.rb
|
120
126
|
- spec/spec_helper.rb
|