noopi 1.0.4 → 1.0.5

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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in noopi.gemspec
4
+ gemspec
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,91 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'cgi'
4
+
5
+ class Noopi
6
+
7
+ @@api_server = 'api.noop.fr'
8
+ @@api_version = 1
9
+ @@api_key = nil
10
+
11
+ attr_accessor :api_key
12
+
13
+ def initialize( api_key = nil )
14
+ @api_key = api_key || @@api_key
15
+ end
16
+
17
+ def shorten( *args )
18
+ long_url = CGI.escape( args.shift )
19
+ options = ( !args.last.nil? and args.last.is_a?( Hash ) ) ? args.pop : {}
20
+
21
+ params = {}
22
+ params[:apiKey] = @api_key
23
+ params[:long_url] = long_url
24
+
25
+ request = Net::HTTP::Get.new( "/v#{@@api_version}/shorten?#{hash_to_params( params )}" )
26
+
27
+ return send_request( request )
28
+ end
29
+
30
+ def list( *args )
31
+ params = {}
32
+ params[:apiKey] = @api_key
33
+
34
+ request = Net::HTTP::Get.new( "/v#{@@api_version}/list?#{hash_to_params( params )}" )
35
+
36
+ return send_request( request )
37
+ end
38
+
39
+ def statistics( *args )
40
+ hash_key = args.first
41
+ params = {}
42
+ params[:apiKey] = @api_key
43
+ params[:hash] = hash_key
44
+
45
+ request = Net::HTTP::Get.new( "/v#{@@api_version}/statistics?#{hash_to_params( params )}" )
46
+
47
+ return send_request( request )
48
+ end
49
+
50
+ def self.api_key=( value )
51
+ @@api_key = value
52
+ end
53
+
54
+ def self.api_key
55
+ @@api_key
56
+ end
57
+
58
+ def self.api_version=( value )
59
+ @@api_version = value
60
+ end
61
+
62
+ def self.api_version
63
+ @@api_version
64
+ end
65
+
66
+ def self.api_server=( value )
67
+ @@api_version = value
68
+ end
69
+
70
+ def self.api_server
71
+ @@api_version
72
+ end
73
+
74
+ private
75
+ def send_request( request )
76
+ http = Net::HTTP.new( @@api_server )
77
+ result = http.request( request )
78
+
79
+ return JSON.parse( result.body )
80
+ end
81
+
82
+ def hash_to_params( hash )
83
+ params = []
84
+ hash.each do |k, v|
85
+ params << "#{k}=#{CGI.escape( v )}"
86
+ end
87
+
88
+ return params.join("&")
89
+ end
90
+
91
+ end
@@ -0,0 +1,3 @@
1
+ class Noopi
2
+ VERSION = "1.0.5"
3
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "noopi/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "noopi"
7
+ s.version = Noopi::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Julien DUMAS"]
10
+ s.email = ["julien7.dumas@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{n/a}
13
+ s.description = %q{n/a}
14
+ s.add_dependency( 'json', '>= 1.5.1' )
15
+
16
+ s.rubyforge_project = "noopi"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: noopi
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.4
5
+ version: 1.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Julien DUMAS
@@ -33,8 +33,13 @@ extensions: []
33
33
 
34
34
  extra_rdoc_files: []
35
35
 
36
- files: []
37
-
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - Rakefile
40
+ - lib/noopi.rb
41
+ - lib/noopi/version.rb
42
+ - noopi.gemspec
38
43
  has_rdoc: true
39
44
  homepage: ""
40
45
  licenses: []