inkling_api 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/inkling_api.gemspec CHANGED
@@ -23,8 +23,11 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency('hashie', '~> 1.1.0')
24
24
  s.add_dependency('activesupport', '~> 3.0.9')
25
25
  s.add_dependency('i18n', '~> 0.6.0')
26
+ s.add_dependency('httparty', '~> 0.7.8')
27
+ s.add_dependency('builder', '~> 3.0.0')
26
28
 
27
- s.add_development_dependency('rspec')
29
+ s.add_development_dependency('rspec', '~> 2.6.0')
30
+ s.add_development_dependency('rspec-core', '~> 2.6.0')
28
31
  s.add_development_dependency('json_spec', '~> 0.6.0')
29
32
  s.add_development_dependency('shoulda', '~> 2.11.3')
30
33
  s.add_development_dependency('ruby-debug19')
data/lib/inkling_api.rb CHANGED
@@ -2,6 +2,7 @@ require 'faraday_stack'
2
2
  require 'inkling_api/faraday_middlewares'
3
3
  require 'hashie/mash'
4
4
  require 'inkling_api/activesupport_yaml_hack'
5
+ require 'ruby-debug'
5
6
 
6
7
  module InklingApi
7
8
  module Configuration
@@ -43,11 +44,12 @@ module InklingApi
43
44
  raise "set_url first" unless @url
44
45
  @connection ||= begin
45
46
  conn = Faraday.new(@url) do |b|
47
+ b.use Faraday::Request::UrlEncoded
46
48
  b.use FaradayStack::ResponseJSON, content_type: 'application/json'
47
49
  b.use FaradayMiddlewares::ResponseXMLToHash, content_type: 'application/xml'
48
50
  b.use PreserveRawBody
49
51
  #b.use FaradayStack::Caching, cache, strip_params: %w[access_token client_id] unless cache.nil?
50
- b.response :raise_error
52
+ #b.response :raise_error
51
53
  #b.use Faraday::Response::Logger
52
54
  b.use FaradayStack::Instrumentation
53
55
  b.adapter Faraday.default_adapter
@@ -65,6 +67,32 @@ module InklingApi
65
67
  request.params = params if params
66
68
  end
67
69
  end
70
+
71
+ def post(path, payload, params = nil)
72
+ connection.post do |request|
73
+ request.url path
74
+ request.headers['Content-Type'] = 'application/xml'
75
+ request.body = payload
76
+ request.params if params
77
+ end
78
+ end
79
+
80
+ def put(path, payload, params = nil)
81
+ connection.put do |request|
82
+ request.url path
83
+ request.headers['Content-Type'] = 'application/xml'
84
+ request.body = payload
85
+ request.params if params
86
+ end
87
+ end
88
+
89
+ def delete(path, params = nil)
90
+ connection.delete(path)
91
+ end
92
+
93
+ def publish(path, params = nil)
94
+ connection.post(path)
95
+ end
68
96
  end
69
97
 
70
98
  module ApiMethods
@@ -74,6 +102,30 @@ module InklingApi
74
102
  raw ? response.env[:raw_body] : response.body
75
103
  end
76
104
 
105
+ def post(path, payload, params = nil)
106
+ raw = params && params.delete(:raw)
107
+ response = super
108
+ raw ? response.env[:raw_body] : response.body
109
+ end
110
+
111
+ def put(path, payload, params = nil)
112
+ raw = params && params.delete(:raw)
113
+ response = super
114
+ raw ? response.env[:raw_body] : response.body
115
+ end
116
+
117
+ def delete(path, params = nil)
118
+ raw = params && params.delete(:raw)
119
+ response = super
120
+ raw ? response.enc[:raw_body] : response.body
121
+ end
122
+
123
+ def publish(path, params = nil)
124
+ raw = params && params.delete(:raw)
125
+ response = super
126
+ raw ? response.enc[:raw_body] : response.body
127
+ end
128
+
77
129
  def market(market_id, *args)
78
130
  get("markets/#{market_id}.xml", *args)
79
131
  end
@@ -81,6 +133,28 @@ module InklingApi
81
133
  def markets(*args)
82
134
  get("markets.json", *args)
83
135
  end
136
+
137
+ def new_market(question, class_type, ends_at, tag_list)
138
+ market_data = { :'name' => question,
139
+ :'class-type' => class_type,
140
+ :'ends-at' => ends_at,
141
+ :'tag-list' => tag_list
142
+ }
143
+ post("markets.xml", market_data.to_xml(:root => "market"), :content_type => 'application/xml')
144
+ end
145
+
146
+ def update_market(market_id, question)
147
+ market_data = { :'name' => question }
148
+ put("markets/#{market_id}.xml", market_data.to_xml(:root => "market"), :content_type => 'application/xml')
149
+ end
150
+
151
+ def delete_market(market_id)
152
+ delete("markets/#{market_id}.xml", :content_type => 'application/xml')
153
+ end
154
+
155
+ def publish_market(market_id)
156
+ publish("markets/#{market_id}.xml", :content_type => 'application/xml')
157
+ end
84
158
  end
85
159
 
86
160
  extend Configuration
@@ -4,7 +4,7 @@ module FaradayMiddlewares
4
4
  require 'nokogiri'
5
5
  Nokogiri::Slop
6
6
  end
7
-
7
+
8
8
  define_parser do |body|
9
9
  Nokogiri::Slop body
10
10
  end
@@ -1,3 +1,3 @@
1
1
  module InklingApi
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -14,7 +14,8 @@ describe InklingApi do
14
14
  InklingApi
15
15
  end
16
16
 
17
- %w( configure connection get markets market ).each do |meth|
17
+ %w( configure connection get post put delete markets market new_market
18
+ update_market delete_market publish_market).each do |meth|
18
19
  it "should respond to #{meth}" do
19
20
  inkling_api.should respond_to(meth.to_sym)
20
21
  end
@@ -33,4 +34,34 @@ describe InklingApi do
33
34
  markets = inkling_api.markets
34
35
  inkling_api.market(markets.first["id"]).should be_a(Hash)
35
36
  end
37
+
38
+ it "should create a market" do
39
+ question = "Is this test going to pass?"
40
+ class_type = "Exclusive"
41
+ ends_at = "2014-05-05T02:20:30-05:00"
42
+ tag_list = "tests"
43
+ inkling_api.new_market(question, class_type, ends_at, tag_list)["market"]["id"].should_not be_nil
44
+ end
45
+
46
+ it "should update a market" do
47
+ market_id = 37810
48
+ question = "Testing predicition widget"
49
+ # FIXME: This will raise a <Faraday::Error::ParsingError> because it expects XML to be returned
50
+ # However, Inkling Markets returns nothing when updating existing markets
51
+ # inkling_api.update_market(market_id, question).should be_a(String)
52
+ end
53
+
54
+ it "should delete a market" do
55
+ market_id = 38271
56
+ lambda do
57
+ inkling_api.delete_market(market_id)
58
+ end.should_not raise_error
59
+ end
60
+
61
+ it "should publish a market" do
62
+ market_id = 38370
63
+ lambda do
64
+ inkling_api.publish_market(market_id)
65
+ end.should_not raise_error
66
+ end
36
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inkling_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,12 +11,12 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-08-09 00:00:00.000000000 +00:00
14
+ date: 2011-08-15 00:00:00.000000000 +00:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: faraday
19
- requirement: &19673880 !ruby/object:Gem::Requirement
19
+ requirement: &21966720 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
22
  - - ~>
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: 0.7.4
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *19673880
27
+ version_requirements: *21966720
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: faraday-stack
30
- requirement: &19657860 !ruby/object:Gem::Requirement
30
+ requirement: &21966220 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ~>
@@ -35,10 +35,10 @@ dependencies:
35
35
  version: 0.1.3
36
36
  type: :runtime
37
37
  prerelease: false
38
- version_requirements: *19657860
38
+ version_requirements: *21966220
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: hashie
41
- requirement: &19657280 !ruby/object:Gem::Requirement
41
+ requirement: &21965760 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ~>
@@ -46,10 +46,10 @@ dependencies:
46
46
  version: 1.1.0
47
47
  type: :runtime
48
48
  prerelease: false
49
- version_requirements: *19657280
49
+ version_requirements: *21965760
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: activesupport
52
- requirement: &19656700 !ruby/object:Gem::Requirement
52
+ requirement: &21965300 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
55
  - - ~>
@@ -57,10 +57,10 @@ dependencies:
57
57
  version: 3.0.9
58
58
  type: :runtime
59
59
  prerelease: false
60
- version_requirements: *19656700
60
+ version_requirements: *21965300
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: i18n
63
- requirement: &19656120 !ruby/object:Gem::Requirement
63
+ requirement: &21964840 !ruby/object:Gem::Requirement
64
64
  none: false
65
65
  requirements:
66
66
  - - ~>
@@ -68,21 +68,54 @@ dependencies:
68
68
  version: 0.6.0
69
69
  type: :runtime
70
70
  prerelease: false
71
- version_requirements: *19656120
71
+ version_requirements: *21964840
72
+ - !ruby/object:Gem::Dependency
73
+ name: httparty
74
+ requirement: &21964380 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ~>
78
+ - !ruby/object:Gem::Version
79
+ version: 0.7.8
80
+ type: :runtime
81
+ prerelease: false
82
+ version_requirements: *21964380
83
+ - !ruby/object:Gem::Dependency
84
+ name: builder
85
+ requirement: &21963920 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: 3.0.0
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: *21963920
72
94
  - !ruby/object:Gem::Dependency
73
95
  name: rspec
74
- requirement: &19655620 !ruby/object:Gem::Requirement
96
+ requirement: &21963460 !ruby/object:Gem::Requirement
75
97
  none: false
76
98
  requirements:
77
- - - ! '>='
99
+ - - ~>
78
100
  - !ruby/object:Gem::Version
79
- version: '0'
101
+ version: 2.6.0
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: *21963460
105
+ - !ruby/object:Gem::Dependency
106
+ name: rspec-core
107
+ requirement: &21963000 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ~>
111
+ - !ruby/object:Gem::Version
112
+ version: 2.6.0
80
113
  type: :development
81
114
  prerelease: false
82
- version_requirements: *19655620
115
+ version_requirements: *21963000
83
116
  - !ruby/object:Gem::Dependency
84
117
  name: json_spec
85
- requirement: &19654840 !ruby/object:Gem::Requirement
118
+ requirement: &21962540 !ruby/object:Gem::Requirement
86
119
  none: false
87
120
  requirements:
88
121
  - - ~>
@@ -90,10 +123,10 @@ dependencies:
90
123
  version: 0.6.0
91
124
  type: :development
92
125
  prerelease: false
93
- version_requirements: *19654840
126
+ version_requirements: *21962540
94
127
  - !ruby/object:Gem::Dependency
95
128
  name: shoulda
96
- requirement: &19654220 !ruby/object:Gem::Requirement
129
+ requirement: &21962080 !ruby/object:Gem::Requirement
97
130
  none: false
98
131
  requirements:
99
132
  - - ~>
@@ -101,10 +134,10 @@ dependencies:
101
134
  version: 2.11.3
102
135
  type: :development
103
136
  prerelease: false
104
- version_requirements: *19654220
137
+ version_requirements: *21962080
105
138
  - !ruby/object:Gem::Dependency
106
139
  name: ruby-debug19
107
- requirement: &19653720 !ruby/object:Gem::Requirement
140
+ requirement: &21961700 !ruby/object:Gem::Requirement
108
141
  none: false
109
142
  requirements:
110
143
  - - ! '>='
@@ -112,7 +145,7 @@ dependencies:
112
145
  version: '0'
113
146
  type: :development
114
147
  prerelease: false
115
- version_requirements: *19653720
148
+ version_requirements: *21961700
116
149
  description:
117
150
  email:
118
151
  - david@isotope11.com