the_adult_company 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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 the_adult_company.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ How to install
2
+ ==============
3
+ Terminal
4
+ --------
5
+ $ gem install the_adult_company
6
+
7
+ Gemfile
8
+ -------
9
+ gem 'the_adult_company'
10
+
11
+ How to use
12
+ ==========
13
+
14
+ require 'the_adult_company'
15
+
16
+ TheAdultCompany.login = 'username'
17
+ TheAdultCompany.password = 'password'
18
+
19
+ sales = TheAdultCompany.find( :from => Time.now - 86400 ) # equivalent to TheAdultCompany.find( :from => Time.now - 86400, :to => Time.now )
20
+ sales.each do |sale|
21
+ puts "Sale ID: #{sale.id}"
22
+ puts "Total: $#{sale.payout}"
23
+ puts "----------------------------------------------"
24
+ end
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,72 @@
1
+ require "the_adult_company/version"
2
+
3
+ module TheAdultCompany
4
+
5
+ require 'net/http'
6
+ require 'rexml/document'
7
+ require 'time'
8
+
9
+ API_URI = URI.parse( "http://www.the-adult-company.com/private/fr/exports/sales.php" )
10
+ UserAgent = "TheAdultCompany API/Ruby Wrapper v#{VERSION}"
11
+ Sale = Struct.new( :id, :date, :sub_account, :customer_id, :tracking, :payout, :country, :params, :product, :type, :periodicity, :extra, :duration, :origine_id )
12
+
13
+ @@login = nil
14
+ @@password = nil
15
+ @@debug = false
16
+
17
+ def self.login=( val )
18
+ @@login = val
19
+ end
20
+
21
+ def self.password=( val )
22
+ @@password = val
23
+ end
24
+
25
+ def self.find( *args )
26
+ sales = []
27
+ options = args.pop
28
+ options = {} if options.nil?
29
+
30
+ options[:from] = Time.now if options[:from].nil?
31
+ options[:to] = Time.now if options[:to].nil?
32
+
33
+ path = "#{API_URI.path}?login=#{@@login}&passwd=#{@@password}&time1=#{options[:from].to_i}&time2=#{options[:to].to_i}&format=xml"
34
+ req = Net::HTTP::Get.new( path )
35
+ http = Net::HTTP::new( API_URI.host, API_URI.port )
36
+ http.set_debug_output( $stdout ) if @@debug == true
37
+ result = http.request( req )
38
+
39
+ unless result.body.slice( 0, 5 ) == 'ERROR'
40
+ doc = REXML::Document.new( result.body )
41
+ doc.root.each_element('sale') do |item|
42
+ id = item.attributes['id']
43
+ date = Time.parse( item.get_elements('sale_date').first.text )
44
+ sub_account = item.get_elements('sub_account').first.text
45
+ customer_id = item.get_elements('customer_id').first.text
46
+ tracking = item.get_elements('tracking').first.text
47
+ payout = item.get_elements('payout').first.text
48
+ country = item.get_elements('country').first.text
49
+ params = item.get_elements('params').first.text
50
+ product = item.get_elements('product').first.text
51
+ type = item.get_elements('type').first.text
52
+ periodicity = item.get_elements('periodicity').first.text
53
+ extra = item.get_elements('extra').first.text
54
+ duration = item.get_elements('duration').first.text
55
+
56
+ sale = Sale.new( id, date, sub_account, customer_id, tracking, payout, country, params, product, type, periodicity, extra, duration )
57
+ sales << sale
58
+ end
59
+ else
60
+ x = result.body.split(" ")
61
+ x.shift
62
+
63
+ raise Error, x.join(" ")
64
+ end
65
+
66
+ return sales
67
+ end
68
+
69
+ class Error < Exception
70
+ end
71
+
72
+ end
@@ -0,0 +1,3 @@
1
+ module TheAdultCompany
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "the_adult_company/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "the_adult_company"
7
+ s.version = TheAdultCompany::VERSION
8
+ s.authors = ["Julien Dumas"]
9
+ s.email = ["julien.dumas@emediad.fr"]
10
+ s.homepage = "http://the-adult-company.com"
11
+ s.summary = %q{Wrapper to The Adult Company API}
12
+ s.description = %q{Wrapper to The Adult Company API}
13
+
14
+ s.rubyforge_project = "the_adult_company"
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
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: the_adult_company
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Julien Dumas
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-13 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Wrapper to The Adult Company API
15
+ email:
16
+ - julien.dumas@emediad.fr
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - README.md
24
+ - Rakefile
25
+ - lib/the_adult_company.rb
26
+ - lib/the_adult_company/version.rb
27
+ - the_adult_company.gemspec
28
+ homepage: http://the-adult-company.com
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project: the_adult_company
48
+ rubygems_version: 1.8.6
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: Wrapper to The Adult Company API
52
+ test_files: []