pfapi 0.1.0

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.
data/.gitignore ADDED
@@ -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 pfapi.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ gem-pfapi
2
+ =========
3
+
4
+ ruby gem for PF-API
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,12 @@
1
+ module Pfapi
2
+
3
+ PF_BASE_URL = "http://pageformant.de"
4
+ PF_API_ENDPOINT = "/api/betreiber/nvp/"
5
+ PF_API_VERSION = "1.0"
6
+
7
+
8
+ module ACK
9
+ SUCCESS = 'SUCCESS'
10
+ ERROR = 'ERROR'
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Pfapi
2
+ VERSION = "0.1.0"
3
+ end
data/lib/pfapi.rb ADDED
@@ -0,0 +1,79 @@
1
+ require "pfapi/version"
2
+ require "pfapi/settings"
3
+ require 'net/http'
4
+ require 'cgi'
5
+
6
+ module Pfapi
7
+ class PageformantException < Exception
8
+ def initialize(errStr, errCode = 0)
9
+ super errStr
10
+ @errorCode = Integer(errCode)
11
+ end
12
+
13
+ def errorCode
14
+ @errorCode
15
+ end
16
+ end
17
+
18
+ class PageformantAPI
19
+ attr_accessor :lastError
20
+
21
+ def initialize(key, passwd)
22
+ @apiKey = key
23
+ @apiPasswd = passwd
24
+ @lastError = nil
25
+
26
+ self
27
+ end
28
+
29
+ def sendMessage(srvID, message, link, userSpecID = nil)
30
+ @lastError = nil
31
+
32
+ params = defaultParams
33
+ params['METHOD'] = 'PostMessage'
34
+ params['SERVICEID'] = srvID.to_s
35
+ params['MESSAGE'] = message
36
+ params['LINK'] = link
37
+ params['USERSPECID'] =
38
+ if userSpecID.nil?
39
+ ''
40
+ else
41
+ userSpecID.to_s
42
+ end
43
+
44
+ begin
45
+ sendAPIRequest(params)
46
+ rescue => err
47
+ @lastError = PageformantException.new(err.message)
48
+ end
49
+
50
+ @lastError.nil?
51
+ end
52
+
53
+ private
54
+
55
+ def defaultParams
56
+ {
57
+ 'APIVERSION'=> Pfapi::PF_API_VERSION,
58
+ 'APIKEY'=>@apiKey,
59
+ 'APIPASSWD'=>@apiPasswd
60
+ }
61
+ end
62
+
63
+ def sendAPIRequest(params)
64
+ response = Net::HTTP.post_form(
65
+ URI("#{Pfapi::PF_BASE_URL}#{Pfapi::PF_API_ENDPOINT}"), params)
66
+ handleResponse(response)
67
+ end
68
+
69
+ def handleResponse(response)
70
+ respQuery = CGI.parse(response.body)
71
+ if respQuery['ACK'][0] != Pfapi::ACK::SUCCESS
72
+ errStr = respQuery['ERRSTR'][0]
73
+ errCode = respQuery['ERRCODE'][0]
74
+ @lastError = Pfapi::PageformantException.new(errStr, errCode)
75
+ end
76
+ end
77
+ end
78
+ end
79
+
data/pfapi.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "pfapi/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "pfapi"
7
+ s.version = Pfapi::VERSION
8
+ s.authors = ["Dimitri Korsch"]
9
+ s.email = ["korschdima@yahoo.de"]
10
+ s.homepage = ""
11
+ s.summary = %q{The official PageFormant-API accessor}
12
+ s.description = %q{This gem allows you to connect to the PageFormant-API and use all API-functions.}
13
+
14
+ s.rubyforge_project = "pfapi"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pfapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dimitri Korsch
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-18 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: This gem allows you to connect to the PageFormant-API and use all API-functions.
15
+ email:
16
+ - korschdima@yahoo.de
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - README.md
24
+ - Rakefile
25
+ - lib/pfapi.rb
26
+ - lib/pfapi/settings.rb
27
+ - lib/pfapi/version.rb
28
+ - pfapi.gemspec
29
+ homepage: ''
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project: pfapi
49
+ rubygems_version: 1.8.16
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: The official PageFormant-API accessor
53
+ test_files: []