tipjoy 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/tipjoy.rb +1 -1
- data/lib/tipjoy/account.rb +2 -2
- data/lib/tipjoy/result_error.rb +7 -1
- data/lib/tipjoy/tipjoy_requestor.rb +2 -2
- data/lib/tipjoy/transaction.rb +36 -16
- data/spec/lib/tipjoy/transaction_spec.rb +57 -0
- data/tipjoy.gemspec +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.11
|
data/lib/tipjoy.rb
CHANGED
data/lib/tipjoy/account.rb
CHANGED
@@ -3,8 +3,8 @@ module Tipjoy
|
|
3
3
|
include Tipjoy::Requestor
|
4
4
|
include Tipjoy::BulkInitializer
|
5
5
|
|
6
|
-
EXISTS_PATH = "/
|
7
|
-
CREATE_PATH = "/
|
6
|
+
EXISTS_PATH = "/user/exists/"
|
7
|
+
CREATE_PATH = "/createTwitterAccount/"
|
8
8
|
|
9
9
|
attr_accessor :username
|
10
10
|
attr_accessor :user_id
|
data/lib/tipjoy/result_error.rb
CHANGED
@@ -21,7 +21,7 @@ module Tipjoy
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def tipjoy_request(method, url, data={})
|
24
|
-
Tipjoy.logger.error("requesting via #{method} " + url + "with args " + data.inspect)
|
24
|
+
Tipjoy.logger.error("requesting via #{method} " + url + " with args " + data.inspect)
|
25
25
|
response = tipjoy_http_request(method, url, data)
|
26
26
|
|
27
27
|
if !(200..299).include?(response.code.to_i)
|
@@ -34,7 +34,7 @@ module Tipjoy
|
|
34
34
|
|
35
35
|
if json['result'] != 'success'
|
36
36
|
Tipjoy.logger.error(" ResultError " + json.inspect)
|
37
|
-
raise ::Tipjoy::ResultError.new(json
|
37
|
+
raise ::Tipjoy::ResultError.new(json)
|
38
38
|
end
|
39
39
|
|
40
40
|
Tipjoy.logger.error(" response: " + json.inspect)
|
data/lib/tipjoy/transaction.rb
CHANGED
@@ -1,27 +1,47 @@
|
|
1
1
|
module Tipjoy
|
2
2
|
class Transaction
|
3
|
-
|
3
|
+
include Tipjoy::Requestor
|
4
4
|
include Tipjoy::BulkInitializer
|
5
5
|
|
6
|
+
SHOW_SINGLE_PATH = '/transaction/show/'
|
7
|
+
|
6
8
|
attr_accessor :transaction_id,
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
9
|
+
:username,
|
10
|
+
:userid,
|
11
|
+
:date_joined,
|
12
|
+
:is_loan,
|
13
|
+
:verified,
|
14
|
+
:permalink,
|
15
|
+
:time,
|
16
|
+
:pretty_time,
|
17
|
+
:amount,
|
18
|
+
:twitter_username,
|
19
|
+
:twitter_user_id,
|
20
|
+
:profile_image_url,
|
21
|
+
:tweet_id,
|
22
|
+
:tweet_message,
|
23
|
+
:tweet_message_html
|
22
24
|
|
23
25
|
def initialize(options={})
|
24
26
|
assign_attributes(options)
|
25
27
|
end
|
28
|
+
|
29
|
+
def amount=(a)
|
30
|
+
@amount = a.to_f
|
31
|
+
end
|
32
|
+
|
33
|
+
def is_loan=(is_loan)
|
34
|
+
@is_loan = (is_loan == 1) ? true : false
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.find(id)
|
38
|
+
json = tipjoy_request(:get, TIPJOY_BASE_URL + SHOW_SINGLE_PATH + "?id=" + id.to_s)
|
39
|
+
|
40
|
+
return Transaction.new(json)
|
41
|
+
|
42
|
+
rescue ResultError => e
|
43
|
+
raise e unless e.json["reason"] == "invalid transaction id"
|
44
|
+
return nil
|
45
|
+
end
|
26
46
|
end
|
27
47
|
end
|
@@ -1,5 +1,62 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
2
|
|
3
3
|
describe Tipjoy::Transaction do
|
4
|
+
before do
|
5
|
+
@expected_transaction = {"permalink"=>"http://twitter.com/poopr112",
|
6
|
+
"time"=>"2009-05-27 15:53:21",
|
7
|
+
"twitter_username"=>"poopr111",
|
8
|
+
"is_private"=>false,
|
9
|
+
"twitter_user_id"=>"42670876",
|
10
|
+
"username"=>"poopr111",
|
11
|
+
"transaction_id"=>47702,
|
12
|
+
"amount"=>"1.25",
|
13
|
+
"userid"=>56673,
|
14
|
+
"tweet_message"=>"p $1.25 @poopr112 for api test",
|
15
|
+
"prettyTime"=>"4 days ago", "date_joined"=>"2009-05-26 10:24:07",
|
16
|
+
"verified"=>false,
|
17
|
+
"isLoan"=>1,
|
18
|
+
"tweet_id"=>"1939894288",
|
19
|
+
"tweet_message_html"=>"p $1.25 <a href='http://twitter.com/poopr112'>@poopr112</a> for api test",
|
20
|
+
"profile_image_url"=>"http://s3.amazonaws.com/twitter_thumbs/default.jpg"
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
describe ".find" do
|
25
|
+
it "should return a transaction" do
|
26
|
+
transaction = Tipjoy::Transaction.find(@expected_transaction['transaction_id'])
|
27
|
+
transaction.should_not be_nil
|
28
|
+
transaction.transaction_id.should == @expected_transaction['transaction_id']
|
29
|
+
transaction.amount.should == @expected_transaction['amount'].to_f
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return nil if the transaction is not found" do
|
33
|
+
transaction = Tipjoy::Transaction.find(-1)
|
34
|
+
transaction.should be_nil
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "failure" do
|
38
|
+
before do
|
39
|
+
@requestor = Tipjoy::Transaction
|
40
|
+
@request = Proc.new do
|
41
|
+
Tipjoy::Transaction.find(-1)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it_should_behave_like "tipjoy request maker that might fail"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#is_loan" do
|
50
|
+
it "should be true when response isLoan is 1" do
|
51
|
+
transaction = Tipjoy::Transaction.new({"isLoan"=>1})
|
52
|
+
transaction.is_loan.should be_true
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should be false when response isLoan is 0" do
|
56
|
+
transaction = Tipjoy::Transaction.new({"isLoan"=>0})
|
57
|
+
transaction.is_loan.should be_false
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
4
61
|
|
5
62
|
end
|
data/tipjoy.gemspec
CHANGED