wco_models 3.5.0.7 → 3.5.0.9

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/wco/main.scss +7 -3
  3. data/app/assets/stylesheets/wco/photos.scss +2 -1
  4. data/app/controllers/wco/office_action_templates_controller.rb +3 -0
  5. data/app/controllers/wco/publishers_controller.rb +6 -16
  6. data/app/controllers/wco/reports_controller.rb +6 -5
  7. data/app/controllers/wco/sitemap_paths_controller.rb +14 -2
  8. data/app/controllers/wco/sites_controller.rb +1 -1
  9. data/app/controllers/wco/tags_controller.rb +1 -1
  10. data/app/models/iro/option.rb +37 -4
  11. data/app/models/iro/priceitem.rb +62 -4
  12. data/app/models/tda/option.rb +39 -41
  13. data/app/models/wco/newspartial.rb +3 -2
  14. data/app/models/wco/publisher.rb +29 -8
  15. data/app/models/wco/publisher_d10.rb +50 -0
  16. data/app/models/wco/report.rb +12 -2
  17. data/app/models/wco/site.rb +1 -67
  18. data/app/models/wco/sitemap_path.rb +19 -13
  19. data/app/models/wco/tag.rb +15 -8
  20. data/app/models/wco/utils.rb +1 -1
  21. data/app/views/wco/api/newsproducer/README.txt +4 -0
  22. data/app/views/wco/api/newsproducer/_studio_blue2.js-bk +606 -0
  23. data/app/views/wco/api/newsproducer/_studio_blue2.js-bk2 +898 -0
  24. data/app/views/wco/api/newsproducer/studio_blue2.html.erb-bk +151 -0
  25. data/app/views/wco/office_action_templates/index.haml +1 -1
  26. data/app/views/wco/office_actions/_actions.haml +1 -1
  27. data/app/views/wco/publishers/_form.haml +11 -2
  28. data/app/views/wco/publishers/_post_with.haml +1 -1
  29. data/app/views/wco/reports/_form.haml +13 -2
  30. data/app/views/wco/reports/_index.haml +18 -11
  31. data/app/views/wco/reports/show.haml +6 -1
  32. data/app/views/wco/sitemap_paths/_index.haml +1 -0
  33. data/app/views/wco/sitemap_paths/show.haml +14 -0
  34. data/app/views/wco/sites/index.haml +6 -0
  35. data/app/views/wco/sites/show.haml +1 -1
  36. data/app/views/wco/tags/_form.haml +3 -0
  37. data/config/routes.rb +3 -3
  38. data/lib/shortcuts.rb +1 -1
  39. data/lib/wco_models.rb +1 -1
  40. metadata +8 -3
  41. data/app/views/wco/sitemap_paths/check.haml +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcc37c8b3e5806c47ca4b4acb4faef1776a7ae094625808d985ac524df3b24a7
4
- data.tar.gz: f88b422e76d2746685be893877b6e95b6ff50802f95791ca618f753c8a320728
3
+ metadata.gz: fe726654a262c13acae39364cbe85f35ff9743896e31d230a15801f86dd399f6
4
+ data.tar.gz: d414e7b473e6adb849dd44b57dd0c50616911e84f20b8db3acfefd9aa9fa9e48
5
5
  SHA512:
6
- metadata.gz: 21f1402de0a2d0e81732c42510678f3f0317fb079eb17dd86c3df65bcaa5bf5ebda27942a0f7f012a14b797dacbb2f0958324436109389698b19d4fe6f0b4648
7
- data.tar.gz: 274863dca1341f6abf51af511185b2ca2934da0c0e0bf865c710db73b7b566334681de2ad0e9f78082035b438a0a0f01896eef05efac2cf2bd6eea1f644a0278
6
+ metadata.gz: 8f47d924b4f7b5c93372946ed12ce8f9a0a922fea09d6b94293202d68ddceace0649222882245f981c0dfb1f15ae15dbebd9df83e2f5391b36621f84fb4bad1e
7
+ data.tar.gz: 7c8503c5fbf140a3272d701b660e60582cac151781063e2479bdcf1c0c746b065d07a97263c899ecbaf35968ff867817433517f1a21788b7c534dfc6222fe027
@@ -117,7 +117,10 @@ textarea.monospace {
117
117
  /* D */
118
118
 
119
119
  .d-flex {
120
- align-items: baseline;
120
+ align-items: baseline; /* 2026-11-12: I dont want this alignment */
121
+ }
122
+ .no-align {
123
+ align-items: unset;
121
124
  }
122
125
 
123
126
  .descr {
@@ -343,11 +346,12 @@ table thead.sticky {
343
346
  .w-300px {
344
347
  width: 300px;
345
348
  }
346
-
347
349
  .w-400px {
348
350
  width: 400px;
349
351
  }
350
-
351
352
  .w-500px {
352
353
  width: 500px;
353
354
  }
355
+ .w-600px {
356
+ width: 500px;
357
+ }
@@ -10,10 +10,11 @@
10
10
 
11
11
  div.thumb {
12
12
  margin: 0 0.5em 0.5em 0;
13
+ flex-shrink: 0;
13
14
  }
14
15
 
15
16
  .photos-thumbs img,
16
- img.thumb {
17
+ .thumb {
17
18
  border: 1px solid red;
18
19
  width: 100px;
19
20
  height: 100px;
@@ -25,12 +25,15 @@ class Wco::OfficeActionTemplatesController < Wco::ApplicationController
25
25
  def perform
26
26
  @oat = OAT.find params[:id]
27
27
  authorize! :run, @oat
28
+
28
29
  @conversations = WcoEmail::Conversation.find( params[:conversation_ids] ) if params[:conversation_ids].present?
30
+
29
31
  if 'rb' == @oat.action_type
30
32
  out = eval( @oat.action_exe )
31
33
  elsif 'sh' == @oat.action_type
32
34
  out = `#{@oat.action_exe}`
33
35
  end
36
+
34
37
  flash_notice out
35
38
  redirect_to action: :index
36
39
  end
@@ -12,28 +12,18 @@ class Wco::PublishersController < Wco::ApplicationController
12
12
  redirect_to action: 'index'
13
13
  end
14
14
 
15
- ## this is becoming obsolete - try using do_run_any
16
- def do_run
17
- @publisher = Wco::Publisher.find params[:id]
18
- authorize! :do_run, @publisher
19
-
20
- @publisher.props = OpenStruct.new( JSON.parse params[:publisher][:props] )
21
- # @publisher.do_run binding
22
- @publisher.do_run
23
-
24
- flash_notice "Probably ok"
25
-
26
- redirect_to action: 'index'
27
- end
28
-
29
15
  def do_run_any
30
16
  @publisher = Wco::Publisher.find params[:id]
31
17
  authorize! :do_run, @publisher
32
18
 
33
19
  @publisher.props = OpenStruct.new( JSON.parse params[:props] )
34
- @publisher.do_run
20
+ flag = @publisher.do_run
21
+ if !flag
22
+ flash_alert @publisher.errors
23
+ else
24
+ flash_notice "#do_run_any Probably ok"
25
+ end
35
26
 
36
- flash_notice "Probably ok"
37
27
  redirect_to request.referrer || { action: 'index' }
38
28
  end
39
29
 
@@ -5,16 +5,18 @@ class Wco::ReportsController < Wco::ApplicationController
5
5
 
6
6
  def create
7
7
  params[:report][:tag_ids]&.delete ''
8
+ img_thumb_params = params[:report][:image_thumb]
9
+ params[:report].delete :image_thumb
8
10
 
9
11
  @report = Wco::Report.new params[:report].permit!
10
12
  authorize! :create, @report
11
13
 
12
14
  @report.author = current_profile
13
15
 
14
- if params[:report][:image_thumb]&.[](:image).present?
15
- thumb = @report.image_thumb || @report.build_image_thumb
16
- thumb.image = params[:report][:image_thumb_attributes][:image]
17
- thumb.save
16
+ if img_thumb_params.present?
17
+ @photo = Wco::Photo.new photo: img_thumb_params
18
+ @photo.save!
19
+ @report.image_thumb = @photo
18
20
  end
19
21
 
20
22
  if @report.save
@@ -205,7 +207,6 @@ class Wco::ReportsController < Wco::ApplicationController
205
207
  params[:report][:tag_ids]&.delete ''
206
208
  img_thumb_params = params[:report][:image_thumb]
207
209
  params[:report].delete :image_thumb
208
- # puts! img_thumb_params, 'img_thumb_params'
209
210
 
210
211
  @report = Wco::Report.unscoped.find params[:id]
211
212
  authorize! :update, @report
@@ -7,12 +7,13 @@ class Wco::SitemapPathsController < Wco::ApplicationController
7
7
  @spath = Wco::SitemapPath.find params[:id]
8
8
  authorize! :check, @spath
9
9
  @spath.check
10
+ redirect_to wco.spath_path(@spath)
10
11
  end
11
12
 
12
13
  def clear
13
14
  @spath = Wco::SitemapPath.find params[:id]
14
15
  authorize! :clear, @spath
15
- @spath.update_attributes({ results: [] })
16
+ @spath.logs.destroy_all
16
17
  redirect_to request.referrer || sites_path(@spath.site)
17
18
  end
18
19
 
@@ -29,6 +30,18 @@ class Wco::SitemapPathsController < Wco::ApplicationController
29
30
  end
30
31
  end
31
32
 
33
+ def destroy
34
+ @spath = Wco::SitemapPath.find params[:id]
35
+ site_id = @spath.site_id
36
+ authorize! :destroy, @spath
37
+ if @spath.destroy
38
+ flash_notice 'ok'
39
+ else
40
+ flash_alert 'No luck.'
41
+ end
42
+ redirect_to request.referrer || sites_path(site_id)
43
+ end
44
+
32
45
  def edit
33
46
  @spath = Wco::SitemapPath.find params[:id]
34
47
  @site = @spath.site
@@ -45,7 +58,6 @@ class Wco::SitemapPathsController < Wco::ApplicationController
45
58
  @spath = Wco::SitemapPath.find params[:id]
46
59
  @site = @spath.site
47
60
  authorize! :show, @spath
48
- render 'check'
49
61
  end
50
62
 
51
63
 
@@ -40,7 +40,7 @@ class Wco::SitesController < Wco::ApplicationController
40
40
 
41
41
  def index
42
42
  authorize! :index, Wco::Site
43
- @sites = Wco::Site.all
43
+ @sites = Wco::Site.all.includes( :tags )
44
44
  end
45
45
 
46
46
  def new
@@ -32,7 +32,7 @@ class Wco::TagsController < Wco::ApplicationController
32
32
 
33
33
  def index
34
34
  authorize! :index, Wco::Tag
35
- @tags = Wco::Tag.all.order_by( slug: :asc )
35
+ @tags = Wco::Tag.where( site: nil ).order_by( slug: :asc )
36
36
 
37
37
  tags = Wco::Tag.all.to_a.group_by(&:parent_id)
38
38
  build_tree = lambda do |parent_id|
@@ -8,7 +8,7 @@ class Iro::Option
8
8
  attr_accessor :recompute
9
9
 
10
10
  belongs_to :stock, class_name: 'Iro::Stock', inverse_of: :strategies
11
- def ticker; stock.ticker; end
11
+ field :ticker, type: :string
12
12
 
13
13
  CALL = 'CALL'
14
14
  PUT = 'PUT'
@@ -67,14 +67,47 @@ class Iro::Option
67
67
  return options
68
68
  end
69
69
 
70
+ field :symbol, type: :string
71
+ validates :symbol, uniqueness: true
72
+ index({ symbol: -1 }, { unique: true, name: 'symbol' })
73
+ # def symbol
74
+ # return self[:symbol] if self[:symbol]
75
+ # self[:symbol] = generate_symbol
76
+ # end
77
+
70
78
  ## for schwab, eg:
71
79
  ## "COST 260306C01030000"
72
- def symbol
80
+ def generate_symbol
73
81
  p_c_ = put_call == 'PUT' ? 'P' : 'C'
74
82
  strike_ = format("%08d", (strike.to_f * 1000).round)
75
83
  sym = "#{stock.ticker.ljust(6)}#{expires_on.strftime("%y%m%d")}#{p_c_}#{strike_}"
76
84
  end
77
85
 
86
+ def self.find_or_create_by_symbol symbol
87
+ option = Iro::Option.where( symbol: symbol ).first
88
+ return option if option
89
+ h = Iro::Option.symbol_to_h symbol
90
+ item = Iro::Option.new({
91
+ stock: Iro::Stock.find_by( ticker: h[:ticker] ),
92
+ ticker: h[:ticker],
93
+ put_call: h[:put_call],
94
+ strike: h[:strike],
95
+ expires_on: h[:expires_on],
96
+ symbol: symbol,
97
+ })
98
+ item.save
99
+ return item
100
+ end
101
+
102
+ ## trash, I can save the symbol every time. 2026-10-04
103
+ # def self.find_by_symbol symbol
104
+ # option = self.where( symbol: symbol ).first
105
+ # return option if option
106
+ # h = Iro::Option.symbol_to_h symbol
107
+ # Iro::Option.where( h ).first
108
+ # end
109
+
110
+
78
111
  =begin
79
112
  symbol = "META 260424P00500000"
80
113
  =end
@@ -83,7 +116,7 @@ class Iro::Option
83
116
  date_str = symbol[6,6]
84
117
  type = symbol[12] == 'P' ? 'PUT' : 'CALL'
85
118
  strike_str = symbol[13,8]
86
- expires_on = Date.strptime(date_str, "%y%m%d")
119
+ expires_on = Date.strptime(date_str, "%y%m%d").to_s
87
120
  strike = strike_str.to_i / 1000.0
88
121
  return {
89
122
  ticker: ticker,
@@ -92,7 +125,7 @@ class Iro::Option
92
125
  expires_on: expires_on,
93
126
  }
94
127
  end
95
- def symbol_to_h
128
+ def to_h
96
129
  self.class.symbol_to_h symbol
97
130
  end
98
131
 
@@ -21,18 +21,19 @@ class Iro::Priceitem
21
21
  field :bidSize, type: Integer
22
22
  field :ask, type: Float
23
23
  field :askSize, type: Integer
24
- field :last, type: Float ## this is important
24
+ field :last, type: Float ## this is important?
25
+ field :mark, type: Float ## no, this is important. (bid+ask)/2
25
26
 
26
27
  field :openPrice, type: Float
27
28
  field :lowPrice, type: Float
28
29
  field :highPrice, type: Float
29
30
  field :closePrice, type: Float
30
31
 
31
- field :quote_at, type: DateTime ## this is important, the timestamp mostly used for analysis
32
+ field :quote_at, type: DateTime ## this is important?
32
33
  field :quoteTimeInLong, type: Integer
33
- field :timestamp, type: Integer ## do not use?!
34
+ field :timestamp, type: Integer ## do not use?
34
35
  field :totalVolume, type: Integer
35
- field :mark, type: Float
36
+
36
37
  field :exchangeName, type: String
37
38
  field :volatility, type: Float
38
39
 
@@ -43,6 +44,63 @@ class Iro::Priceitem
43
44
  field :openInterest, type: Integer
44
45
  field :strikePrice, type: Float
45
46
 
47
+ def self.create_from_chains!
48
+ Iro::Iro.schwab_exec_sync ## should be schwab_data_sync()
49
+
50
+ stocks = Iro::Stock.active
51
+ fridays = 3.times.map { |i| ( Date.current.next_occurring(:friday) + i.weeks ).to_s }
52
+
53
+ stocks.each do |stock|
54
+ puts "+++ Getting #{stock.ticker}..."
55
+ response = Tda::Option.get_chains({
56
+ ticker: stock.ticker,
57
+ fromDate: fridays[0],
58
+ toDate: fridays.last,
59
+ strikeCount: 10,
60
+ })
61
+ # puts! response.keys, 'response.keys'
62
+ # puts! response['symbol'], 'response symbol'
63
+ # sleep 10
64
+
65
+ first_val = nil
66
+ ['callExpDateMap', 'putExpDateMap'].each do |which_map|
67
+
68
+ response[which_map].each do |_date, strikes|
69
+ if fridays.include?( _date.split(':')[0] )
70
+ strikes.each do |_strike, vals|
71
+ vals.each do |val|
72
+ if !first_val
73
+ first_val = val
74
+ puts! val.keys, 'val keys'
75
+ end
76
+
77
+ option = Iro::Option.find_or_create_by_symbol( val['symbol'] )
78
+
79
+ # opt = OpenStruct.new val
80
+ pi = Iro::Priceitem.new( val.slice( 'expirationDate',
81
+ 'putCall', 'symbol', 'exchangeName', 'bid', 'ask',
82
+ 'last', 'mark', 'bidSize', 'askSize', 'totalVolume', 'quoteTimeInLong', 'volatility',
83
+ 'delta', 'gamma', 'theta', 'openInterest', 'strikePrice' ) )
84
+ pi.stock = stock
85
+ pi.option = option
86
+ pi.quote_at = Time.at( val['quoteTimeInLong'] / 1000 )
87
+ pi.ticker = stock.ticker
88
+ pi.save!
89
+
90
+ # puts! pi
91
+ print '.'
92
+
93
+
94
+ end
95
+ end
96
+ end ## end fridays.include?
97
+ end
98
+
99
+ end ## which_map
100
+ end
101
+
102
+ end
103
+
46
104
  def self.my_find props={}
47
105
  lookup = { '$lookup': {
48
106
  'from': 'iro_price_items',
@@ -1,16 +1,7 @@
1
1
 
2
2
  require 'httparty'
3
3
 
4
- =begin
5
- class Schwab
6
- include HTTParty
7
- debug_output $stdout
8
- base_uri 'https://api.schwabapi.com/marketdata/v1'
9
- end
10
- =end
11
-
12
4
  class Tda::Option
13
-
14
5
  include ::HTTParty
15
6
  # debug_output $stdout
16
7
  base_uri 'https://api.schwabapi.com/marketdata/v1'
@@ -18,7 +9,7 @@ class Tda::Option
18
9
 
19
10
  ##
20
11
  ## Get entire chains for a ticker
21
- ## params: { ticker, force }
12
+ ## params: { ticker, force, strikeCount, fromDate (yyyy-mm-dd), toDate }
22
13
  ##
23
14
  ## 2024-08-09 :: Continue
24
15
  ## 2024-08-21 :: Continue : )
@@ -29,7 +20,10 @@ class Tda::Option
29
20
  return JSON.parse File.read filename
30
21
 
31
22
  else
32
- query = { symbol: params[:ticker] } ## use 'GME' as symbol here even though a symbol is eg 'GME_021023P2.5'
23
+ query = { symbol: params[:ticker] } ## says query[:symbol], not ticker.
24
+ query[:strikeCount] = params[:strikeCount] if params[:strikeCount]
25
+ query[:fromDate] = params[:fromDate] if params[:fromDate]
26
+ query[:toDate] = params[:toDate] if params[:toDate]
33
27
  # puts! query, 'query'
34
28
 
35
29
  headers = {
@@ -37,40 +31,30 @@ class Tda::Option
37
31
  Authorization: "Bearer #{Iro::Iro.schwab_data_token}",
38
32
  }
39
33
  path = "/chains"
40
- out = self.get path, {
41
- headers: headers,
42
- query: query }
43
- timestamp = DateTime.parse out.headers['date']
44
- out = out.parsed_response
45
- # puts! out, 'outs'
34
+ response = self.get path, { headers: headers, query: query }
35
+ timestamp = DateTime.parse response.headers['date']
36
+ response = response.parsed_response
37
+ puts! response, '/chains got this response'
46
38
 
47
39
  outs = []
48
40
  %w| put call |.each do |contractType|
49
- _out = out["#{contractType}ExpDateMap"]
50
- _out.each do |date, vs| ## date="2023-02-10:5"
41
+ _out = response["#{contractType}ExpDateMap"]
42
+ _out.each do |_date, vs| ## date="2023-02-10:5"
51
43
  vs.each do |strike, _v| ## strike="18.5"
52
44
  _v = _v[0] ## weird, keep
53
45
  # puts! _v, '_v'
54
46
 
55
- v = {
56
- putCall: _v['putCall'],
57
- symbol: _v['symbol'],
58
- bid: _v['bid'],
59
- ask: _v['ask'],
60
- last: _v['last'],
61
- totalVolume: _v['totalVolume'],
62
- openInterest: _v['openInterest'],
63
- strikePrice: _v['strikePrice'],
64
- expirationDate: _v['expirationDate'],
65
- }
47
+ v = _v.slice( 'putCall', 'symbol', 'bid', 'ask', 'last', 'mark', 'totalVolume', 'openInterest',
48
+ 'strikePrice', 'expirationDate' )
66
49
  v.each do |k, i|
67
50
  if i == 'NaN'
68
51
  v[k] = nil
69
52
  end
70
53
  end
71
54
 
72
- v[:timestamp] = timestamp
73
- v[:ticker] = params[:ticker]
55
+ v[:timestamp] = timestamp # _v['quoteTimeInLong']/1000.0
56
+ v[:quote_at] = Time.at(_v['quoteTimeInLong'] / 1000.0)
57
+ v[:ticker] = params[:ticker]
74
58
  outs.push( v )
75
59
  end
76
60
  end
@@ -83,8 +67,8 @@ class Tda::Option
83
67
  end
84
68
  end
85
69
 
86
- File.write filename, out.to_json
87
- return out
70
+ File.write filename, JSON.pretty_generate(response)
71
+ return response
88
72
  end
89
73
  end
90
74
 
@@ -96,6 +80,8 @@ class Tda::Option
96
80
  OpenStruct.new ::Tda::Option.get_quotes(params)[0]
97
81
  end
98
82
 
83
+ ## ...for a single symbol.
84
+ ## but use get_quotes_h instead?!
99
85
  ##
100
86
  ## params: contractType, strike, expirationDate, ticker
101
87
  ##
@@ -250,19 +236,23 @@ class Tda::Option
250
236
  end
251
237
 
252
238
  def self.close_credit_call
239
+ throw 'r40 - not implemented'
253
240
  end
254
241
  def self.close_long_debit_call_spread
242
+ throw 'r41 - not implemented'
255
243
  end
256
244
  def self.close_short_debit_put_spread
245
+ throw 'r42 - not implemented'
257
246
  end
258
247
 
259
- def self.get_token
260
- opts = {
261
- grant_type: 'authorization_code',
262
- access_type: 'offline',
263
- code: ::TD_AMERITRADE[:code],
264
- }
265
- end
248
+ ## trash? remove.
249
+ # def self.get_token
250
+ # opts = {
251
+ # grant_type: 'authorization_code',
252
+ # access_type: 'offline',
253
+ # code: ::TD_AMERITRADE[:code],
254
+ # }
255
+ # end
266
256
 
267
257
  def self.create_credit_call outer:, inner:, q:, price:
268
258
  query = {
@@ -307,13 +297,21 @@ class Tda::Option
307
297
  # puts! out, 'created credit call?'
308
298
  end
309
299
  def self.create_long_debit_call_spread
300
+ throw 'r43 - not implemented'
310
301
  end
311
302
  def self.create_short_debit_put_spread
303
+ throw 'r44 - not implemented'
312
304
  end
313
305
 
314
306
 
315
307
  end
316
308
 
309
+
310
+
311
+
312
+
313
+
314
+
317
315
  ##
318
316
  ## From: https://developer.tdameritrade.com/content/place-order-samples
319
317
  ## Buy Limit: Vertical Call Spread
@@ -69,8 +69,9 @@ class Wco::Newspartial
69
69
  ##
70
70
  ## "am_fenrir", ## bad
71
71
  ## am_michael good
72
- ## "af_bella" ## bad
73
- ## "af_jessica", ## good
72
+ ## am_puck good
73
+ ## "af_bella" ## bad
74
+ ## "af_jessica" ## good
74
75
  ##
75
76
  def generate_speech
76
77
  out = HTTParty.post( "#{Wco::Setting.get('HEAD_TTS_ORIGIN')}/v1/synthesize",
@@ -1,4 +1,11 @@
1
1
 
2
+ def url_exists?(url)
3
+ response = HTTParty.head(url, timeout: 5, follow_redirects: true)
4
+ response.code == 200
5
+ rescue StandardError
6
+ false
7
+ end
8
+
2
9
  class Wco::Publisher
3
10
  include Mongoid::Document
4
11
  include Mongoid::Timestamps
@@ -19,26 +26,35 @@ class Wco::Publisher
19
26
  field :post_path
20
27
 
21
28
  has_many :oats, class_name: 'Wco::OfficeActionTemplate'
29
+ has_and_belongs_to_many :tags
22
30
 
23
31
  attr_accessor :props
24
32
 
25
33
  def do_run
26
- @site = site
34
+ @publisher = publisher = self
35
+
36
+ @site = publisher.site
27
37
  @headers = {}
28
38
  @ctx = OpenStruct.new
29
39
 
30
- # puts! context_eval, 'context_eval'
31
- eval( context_eval )
32
- # puts! @ctx, '@ctx'
40
+ puts! publisher.context_eval, 'context_eval'
41
+ eval( publisher.context_eval )
42
+ puts! @ctx, '@ctx'
33
43
 
34
- tmpl = ERB.new post_body_tmpl
44
+ if @abort
45
+ errors.add(:base, 'aborted')
46
+ return false
47
+ end
48
+
49
+ tmpl = ERB.new publisher.post_body_tmpl
35
50
  body = JSON.parse tmpl.result(binding)
36
- # puts! body, 'body'
51
+ puts! body, 'body'
37
52
 
38
53
  out = Wco::HTTParty.post( "#{@site.origin}#{post_path}", {
39
54
  body: body.to_json,
40
55
  headers: @headers,
41
56
  basic_auth: { username: @site.username, password: @site.password },
57
+ debug_output: $stdout,
42
58
  })
43
59
  puts! out.response, 'publisher httparty response'
44
60
  puts! out.body, 'publisher httparty body'
@@ -54,12 +70,17 @@ class Wco::Publisher
54
70
  raise out.body
55
71
  end
56
72
 
57
- eval( after_eval ) if after_eval.present?
73
+ if after_eval.present?
74
+ puts! after_eval, 'after_eval'
75
+ eval( after_eval )
76
+ end
77
+
78
+ return true
58
79
  end
59
80
 
60
81
 
61
82
  def to_s
62
- "#{slug}: #{kind} => #{site}"
83
+ "#{site} :: #{slug}"
63
84
  end
64
85
 
65
86
  def self.list
@@ -0,0 +1,50 @@
1
+
2
+ ##
3
+ ## this doesn't work and was never tested or used.
4
+ ## 2026-11-14
5
+ ##
6
+ class Wco::PublisherD10 < Wco::Publisher
7
+
8
+ def self.context_eval
9
+
10
+ @headers['Content-Type'] = 'application/vnd.api+json'
11
+ @headers['Authorization'] = "Basic base64(#{@site.username}:#{@site.password})"
12
+
13
+ @report = Wco::Report.find @props[:report_id]
14
+
15
+ tags = @publisher.tags.where( site: @site )
16
+ @tags_data = tags.map do |tag|
17
+ { "type": "taxonomy_term--tags", "id": tag.external_id.to_s }
18
+ end.to_json
19
+ puts! @tags_data, '@tags_data'
20
+
21
+ @field_image_thumb_data = ""
22
+ if false || @report.image_thumb
23
+ image_url ||= @report.image_thumb.photo.url(:thumb)
24
+
25
+ uri = URI(image_url)
26
+ image_data = Net::HTTP.get(uri)
27
+ credentials = Base64.strict_encode64("#{@site.username}:#{@site.password}")
28
+
29
+ puts! 'Saving an image...'
30
+ response = HTTParty.post(
31
+ "#{@site.origin}/jsonapi/node/article/field_image_thumb",
32
+ headers: {
33
+ 'Content-Type' => 'application/octet-stream',
34
+ 'Accept' => 'application/vnd.api+json',
35
+ 'Content-Disposition' => 'file; filename="thumbnail.jpg"',
36
+ 'Authorization' => "Basic #{credentials}",
37
+ },
38
+ body: image_data
39
+ )
40
+ puts! response, 'response'
41
+ field_image_thumb_id = response['data']['id']
42
+ @field_image_thumb_data =<<~AOL
43
+ "field_image_thumb": { "data": { "type": "file--file", "id": "#{field_image_thumb_id}" } },
44
+ AOL
45
+ puts! @field_image_thumb_data, '@field_image_thumb_data'
46
+ end
47
+
48
+ end
49
+
50
+ end